Hello!
I have this Code for moveing and jumping: But it is not perfect yet. For exemple, if you keep pressing space than you dont fall down. I have no clue how to solve this. If you any tips than pls help me.
Thanks a lot with the best greetings!
import greenfoot.*; public class Jumper1 extends Actor { private final int GRAVITY = 1; private int velocity; int speed = 1; public Jumper1() { velocity = 5; } public void act() { mover(); fall(); if (Greenfoot.isKeyDown("space") && getY() > getWorld().getHeight() -50) jump(); } public void fall() { setLocation(getX(), getY() + velocity); if (getY() > getWorld().getHeight() -50) velocity = 5; else velocity += GRAVITY; } public void jump() { velocity = -20; } public void mover() { if (Greenfoot.isKeyDown("a")) setLocation(getX() - speed, getY()); if (Greenfoot.isKeyDown("d")) setLocation(getX() + speed, getY()); } }