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

2013/10/31

Starting at a random interval

Baenefin Baenefin

2013/10/31

#
I am trying to get my enemies to jump at a random interval. This is what I have. public class Jumper extends Enemy { int j = 0; boolean onGround; private static final int jumpStrength = 14; GreenfootImage left = new GreenfootImage("JumperLeft.png"); public void act() { j++; if(j == 100); { if (j <= 20) { jump(); } else if (j >= 25) { fall(); } if (j >= 250) { j=0; } } } public void jump() { setVSpeed(-jumpStrength); fall(); } private void checkFall() { if (onGround()) { setVSpeed(0); } } }
danpost danpost

2013/10/31

#
What exactly do you mean by 'jump at a random interval'? That could mean one of several things.
GreenFootWizard3.0 GreenFootWizard3.0

2013/10/31

#
WOW SUPER COOL
Baenefin Baenefin

2013/10/31

#
What I mean, is i want them to jum(); (and fall) at random intervals. If i spawn 3 jumpers now, they all jump at the same time. I would like them to jump randomly
danpost danpost

2013/10/31

#
I guess you could change 'if (j >= 250)' to something like 'if (j >= 225+Greenfoot.getRandomNumber(50))' to vary the intervals.
You need to login to post a reply.