Hi
I have the following code, which allows my main character to fire bullets. I tried to make an integer, called ammo, and giving it the value 15. I then tried to incorporate into my code, that ammo integer -1 whenever i fire a bullet.
The shooting-code works fine, but for some reason i have unlimited ammo - in other words, my ammo integer isn't connected to the shooting code.
Can anyone help me? it would be much appreciated
int ammo;
public void Ditzel()
{
ammo=5;
}
private boolean spaceDown;
public void shoot()
{
if(!spaceDown && Greenfoot.isKeyDown("space"))
{
if(Munition()==true)
{
spaceDown=true;
Bullet bullet = new Bullet();
bullet.setRotation(getRotation());
getWorld().addObject(bullet, getX(), getY());
ammo--;
}
}
if(spaceDown && !Greenfoot.isKeyDown("space"))
{
spaceDown=false;
}
}
public boolean Munition()
{
if(ammo>0)
{
return true;
}
else
{
return false;
}
}
