I've managed to get the character to jump using spacebar key but the jump is active for far too long and the character goes to the top of the screen. could someone take a look: http://www.greenfoot.org/scenarios/8881
public void act() { checkKeys(); if(!checkGround()) { fall(); } else { jumping = false; } }
public void jump() { vSpeed = vSpeed - jumpDistance; fall(); }
public boolean checkGround() { Actor marioLeftFoot = getOneObjectAtOffset(-19, marioHeight, Tile.class); Actor marioRightFoot = getOneObjectAtOffset(19, marioHeight, Tile.class); if (marioLeftFoot == null && marioRightFoot == null) { return false; } marioLeftFoot = getOneObjectAtOffset(-19, marioHeight - 1, Tile.class); marioRightFoot = getOneObjectAtOffset(19, marioHeight - 1, Tile.class); while (marioLeftFoot != null || marioRightFoot != null) { setLocation(getX(), getY() - 1); marioLeftFoot = getOneObjectAtOffset(-19, marioHeight - 1, Tile.class); marioRightFoot = getOneObjectAtOffset(19, marioHeight - 1, Tile.class); } vSpeed = 0; return true; }