This site requires JavaScript, please enable it in your browser!
Greenfoot back
DiplomatikCow
DiplomatikCow wrote ...

2014/11/25

How to end game when all bullets are gone?

DiplomatikCow DiplomatikCow

2014/11/25

#
So I am making this game in which you have 25 bullets, however, I do not know how to stop the game when I am out of bullets. With what I have the Bullets just start going into the negatives.
DiplomatikCow DiplomatikCow

2014/11/25

#
How do I add code to make the game stop once bullets are all gone
danpost danpost

2014/11/25

#
Right after you decrement the bullet count, check it for a zero value:
bulletCount = bulletCount - 1; // after a line something like this
if (bulletCount == 0) Greenfoot.stop(); // add something like this line
DiplomatikCow DiplomatikCow

2014/11/25

#
It tells me that it cannot find the variable bulletCount?
DiplomatikCow DiplomatikCow

2014/11/25

#
       if(Greenfoot.isKeyDown("space") && !shooting)
       {
           getWorld().addObject(new Bullet(), getX(), getY());
           bulletsLeft.add(-1);
           bulletCount = bulletCount - 1;
           if(bulletCount == 0) Greenfoot.stop();
           Space space = (Space)getWorld();//casting
           Greenfoot.playSound("EnergyGun.wav");
           shooting = true;
       }
danpost danpost

2014/11/25

#
Please show the class code for the object that 'bulletsLeft' was created from.
You need to login to post a reply.