Hello
I have the problem where my walk and my jump metods is conflicting so that only one of them can work at a time and i can't seem to figure out where the problem is.
This is my code
Please if someone know the problem I would really appreciate the help
import greenfoot.*; public class Jonas extends Actor { int Imagecycle = 1; int lastKey =0; private int ySpeed; /** * Act - do whatever the Jonas wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { Jump(); Walk(); Image(); } public void Walk() { String key = Greenfoot.getKey(); if("right".equals(key) && lastKey <= 0) { Background background = (Background) getWorld(); background.drawBackgroundImage(); Imagecycle ++; lastKey = 1; } if("left".equals(key) && lastKey >= 1) { Background background = (Background) getWorld(); background.drawBackgroundImage(); Imagecycle ++; lastKey = 0; } } public void Jump() { int groundLevel = getWorld().getHeight() - getImage().getHeight()/2; boolean onGround = (getY() == groundLevel); if (!onGround) // in middle of jump { ySpeed++; // adds gravity effect setLocation(getX(), getY()+ySpeed); // fall (rising slower or falling faster) if (getY()>=groundLevel) // has landed (reached ground level) { setLocation(getX(), groundLevel); // set on ground Greenfoot.getKey(); // clears any key pressed during jump } } else // on ground { if ("space".equals(Greenfoot.getKey())) // jump key detected { ySpeed = -15; // add jump speed setLocation(getX(), getY()+ySpeed); // leave ground } } }