i created a player and i want him to shoot bullet. i understand the logic but i need some help with it. my bullet will just be rect in paint method.
logic:
create bullet class
store in arraylist
print in paint method
in bullet class i set the variables:
Bullet.java
x //x postion y //y postion width //width of bullet height = 10; //height of bullet dx = 5; //speed of bullet boolean hitSpace = false; //if user hit space buttom boolean visable = false; //cant see the bullet int bullet_limit = 50; //set bullet limit. so after 50 no more bullets int bullet_range = 200; //how far can bullet go private ArrayList<Bullet> store_bullets = new ArrayList<Bullet>(); //store bullets
//if user hit space bar than set variables (calling this method in key method in main.) public void hitSPACE() { hitSpace = true; dead = false; } public void MOVE() { if(hitSpace == true) //if user hit space bar { Bullet b = new shoot(x, y); //create bullet store_bullets.add(b); //store in arraylist x+= dx; //change speed if(x > bullet_range) //if it goes above range than dont viable { visable = false; //cant see the bullet } } } //draw bullets from arraylist public void paint(Graphics g) { if(visable == true) //if its visable { for(int w = 0; w < store_bullets.size(); w++)// print from array list { g.fillRect(x, y, width, height); } } }//end of paint method
this is the code where i need help. how to print bullets from arraylist.
for(int w = 0; w < store_bullets.size(); w++) // print from array list { g.fillRect(x, y, width, height); }