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

2018/5/13

Help with changing variables of the actor that has been shot at

SPCWW SPCWW

2018/5/13

#
I'm trying to make a game similar to the Bloons Tower Defense games, i'm having trouble as I need to make it so that each balloon can only be shot by one tower, I'm trying to make it so that when the balloon is in the range the variable "marked" to true and only shoot at it if "marked" = false. Here is my code :
public boolean isBalloonInRange()
    {
        return !getObjectsInRange(100, Balloon.class).isEmpty();
    }
    public void shoot()
    {
        if(isBalloonInRange()&&cooldown<1&&active==true){
            Actor balloon = (Actor) getObjectsInRange(100,  Balloon.class).get(0);
            getWorld().addObject(new Bullet(balloon), getX(), getY());
            balloon.marked=true;
            cooldown=30;
        }            
        cooldown--;
    }
danpost danpost

2018/5/13

#
SPCWW wrote...
I'm trying to make a game similar to the Bloons Tower Defense games, i'm having trouble as I need to make it so that each balloon can only be shot by one tower, I'm trying to make it so that when the balloon is in the range the variable "marked" to true and only shoot at it if "marked" = false. Here is my code << Code Omitted >>
Replace both occurrences of Actor in line 8 with Balloon so marked can be found.
SPCWW SPCWW

2018/5/13

#
It worked! Thanks.
You need to login to post a reply.