i'm making a game and so far i have gravity in the game but i want to make it so the player can jump on to platforms but i can't figure out how to place that into the code that i have, please help.
private int ySpeed;
public void Gravity()
{
int groundLevel = getWorld().getHeight() - getImage().getHeight()/2;
boolean onGround = (getY() == groundLevel);
if (!onGround)
{
ySpeed++;
setLocation(getX(), getY()+ySpeed);
if (getY()>=groundLevel)
{
setLocation(getX(), groundLevel);
Greenfoot.getKey();
}
}
else
{
if ("space".equals(Greenfoot.getKey()))
{
ySpeed = -15;
setLocation(getX(), getY()+ySpeed);
}
}
}
