Hey Guys,
So I'm currently programming a platformer type of game for a major work at school, and I've been able to program a mediocre jump method, but it's absolutely terrible. Basically what happens is, you press the spacebar and then the players Y location should decrease by a set value, and then the player should drop, however, in my code it's telling the player to stay at that increased Y position until the spacebar has been released. I don't really know how to fix this. My code for my jump method is:
public void jump()
{
if (Greenfoot.isKeyDown("space")){
setLocation(getX(), getY() - speed*12);
Greenfoot.delay(1);
fall();
// the hSpeed was just to make the player jump forward or backward when necessary
if (Greenfoot.isKeyDown("d")) {
setLocation(getX() + hSpeed, getY() - speed*12);
Greenfoot.delay(1);
fall();
}
if (Greenfoot.isKeyDown("a")) {
setLocation(getX() - hSpeed, getY() - speed*12);
Greenfoot.delay(1);
fall();
}
if (Greenfoot.isKeyDown("shift")) {
if (Greenfoot.isKeyDown("d")) {
setLocation(getX() + hSpeed*4, getY() - speed*16);
Greenfoot.delay(1);
fall();
}
if (Greenfoot.isKeyDown("a")) {
setLocation(getX() - hSpeed*4, getY() - speed*16);
Greenfoot.delay(1);
fall();
}
}
}
