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

2020/4/28

How to make timer on enemy fire

JoshuaK JoshuaK

2020/4/28

#
I would like to make the enemy fire automatically on a 1 second timer THE ENEMY FIRE CODE public void rocketbullet() { Rocketbullet rocketbullet = new Rocketbullet(); getWorld().addObject(new Rocketbullet(), getX() + (-49), getY()); } PROJECTILE CODE public void act() { setLocation(getX() + speed, getY()); } private int speed = -25;
danpost danpost

2020/4/28

#
int timer;

public void act()
{
    timer++;
    if ((timer == 60)
    {
        timer = 0;
        rocketbullet();
    }
}
Lines 5 thru 10 can be replaced with:
if ((timer = (++timer)%60) == 0) rocketbullet();
JoshuaK JoshuaK

2020/4/29

#
Thanks for the hasty reply :)
You need to login to post a reply.