change bullets!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • game2d
    New Member
    • Apr 2013
    • 59

    change bullets!

    i need some help with java. i am creating a game where i have a player and he shoot bullets. u can also change u types of bullet.
    bullets are just fillOval. and change types of bullets is different colo.

    i have created a class bullet. which just create one bullet.
    than if player hit space bar. than create a bullet and store in arraylist.

    Code:
    if(space)
    {
        bulletObject = new Bullet();    //create bullet
        bulletStore.add(bulletObject);  //store in arraylist
    }
    now to change bullets. i have create a variable call bulletName. if it has a value of 1 than its bullet type is 1. If it has value of 2 than its bullet type is 2.

    if user hit 'f' key than change bullet type.
    Code:
    if(f)
    {
        bulletName ++;  //go to next bullet type
    }
    now to draw the bullets.
    Code:
    pubic void paint(Graphics g)
    {
        if(bulletName == 1)
            g.setColor(Color.green); 
       if(bulletName == 2)
            g.setColor(Color.blue);
        if(bulletName == 3)
            g.setColor(Color.red);
    
         g.fillOval(x,y,width,height);    
    }
    The problem is that if user hit space bar than it will shoot one bullet. than if user hit 'f' key than it will change color of all bullets on screen.

    i want it so that it doesnt change color of bullets on screen. it only change color of bullet that are about to get shoot.change
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Difficult to say without seeing the structure of your code and the order of your events.

    Comment

    Working...