Soooo... I want the arctor to jump at a certain height, and not to go beyond that limit and I don't know where should I set the limit
import greenfoot.*;
public class Dolphin extends Actor
{
private int speed = 7;
private int vSpeed = 0;
private int acceleration = 2;
private int jumpStrenght = 5;
private Label myLabel;
private int count = 0;
public Dolphin (Label label)
{
myLabel = label;
}
public void act()
{
checkKeys();
checkFall();
}
private void checkKeys()
{
if(Greenfoot.isKeyDown("left"))
{
moveLeft();
}
if(Greenfoot.isKeyDown("right"))
{
moveRight();
}
if(Greenfoot.isKeyDown("up"))
{
jump();
count++;
myLabel.setText("COUNT: " + count);
}
}
public void checkFall()
{
if(onGround())
{
vSpeed=0;
}
else
{
fall();
}
}
public boolean onGround()
{
Actor under = getOneObjectAtOffset ( 0, getImage().getHeight()/2, Ground.class);
return under != null;
}
public void fall()
{
setLocation ( getX(), getY() + vSpeed);
vSpeed = vSpeed + acceleration;
}
public void jump()
{
vSpeed = - jumpStrenght;
fall();
}
public void moveRight()
{
setLocation ( getX() + speed, getY());
}
public void moveLeft()
{
setLocation ( getX() - speed, getY());
}
}
