Hi, I've a question:
I want to limit the munition, so the player can only shoot a limited number of times and the remaining munition is shown by a counter. I already archieved the ammo limitation with this code:
How can I connect the shooting method with the AmmoCounter to show how many bullets are left. I already tried to archieve this like this Tutorial: How to access one object from another?, but it was not possible to count backwards fro e.g. 15 to 0 because I was only getting compiling errors.
Another question is, how can I extend the number of available bullets by collecting additional ammo?
For the collection I used this code:
How can I reload the ammo?
public class Ship extends Actor {
public int ammo;
public Ship
{
ammo=15;
}
private boolean spaceDown;
public void shoot(){
if(!spaceDown && Greenfoot.isKeyDown("space"))
{
if(Munition()==true)
{
spaceDown=true;
getWorld().addObject(new Missile(), getX(), getY());
ammo--;
}
}
if(spaceDown && !Greenfoot.isKeyDown("space"))
{
spaceDown=false;
}
}
public boolean Munition(){
if(ammo>0){
return true;
}
else{
return false;
}
}
}
public void collectAmmo(){
Actor ammo = getOneObjectAtOffset(0,0,Ammo.class);
if(ammo !=null){
getWorld().removeObject(ammo);
}
}
