Hello again all,
I am trying to make my enemy jump at a random interval. He also falls. But I can't figure out how to make him stop jumping. Do I need to make a counter?
This is what I have.
Do I need to make an intervall counter or something like that?
public class Enemy extends Actor
{
int timer=0;
int dir=0;
private static final int jumpStrength = 18;
public static final int Speed = 5;
private static final int acceleration = 1;
public int vSpeed = 0;
public void jump()
{
timer++;
setVSpeed(-jumpStrength);
fall();
}
public void setVSpeed(int speed)
{
vSpeed = speed;
}
public void fall()
{
setLocation ( getX(), getY() + vSpeed);
vSpeed = vSpeed + acceleration;
}
private void checkFall()
{
if (onGround()) {
setVSpeed(0);
}
else {
fall();
}
}
public boolean onGround()
{
Block a = (Block) getOneObjectAtOffset(0,32,Block.class);
return a !=null;
}public class Jumper extends Enemy
{
GreenfootImage right = new GreenfootImage("JumperRight.png");
GreenfootImage left = new GreenfootImage("JumperLeft.png");
public void act()
{
if (Greenfoot.getRandomNumber(100) > 90)
jump();
fall();
if (dir==0)
{ setImage(right); }
if (dir==180)
{ setImage(left); }
}
}
