Hi,
i managed to let my character jump to a certain hight. But now i want him to get back down... how can i add some kind of Gravity? I already tried to use setLocation when the Player is not grounded (touching the object ground), but after adding that function he wouldn't jump at all :
Method Grouded:
Method jump:
(if you press longer you jump higher)
public boolean grounded()
{
if(isTouching(Boden.class))
{
return true;
}
else
{
return false;
}
}if(Greenfoot.isKeyDown("space"))
{
if(grounded())
{
setImage("images/jumpking_sprungloading.png");
a = System.currentTimeMillis();
while(Greenfoot.isKeyDown("space"))
{
setImage("images/jumpking_sprungloading.png");
}
b = System.currentTimeMillis();
sprung = (int) b - (int) a;
if(sprung > maxSprung)
{
sprung = maxSprung;
}
setLocation(getX(), getY() - sprung / 4);
}
}
else
{
setImage("images/jumpking_standard.png");
}
