Hey guys I'm trying to create a game about the Olympics and I encountered a problem. My idea was to make the runner move by alternating the right and left keys . Sadly , if you hold down both keys the runner will shoot his way towards the finish line , making the whole game useless. So here's my code :
Please help . Thanks in advance !
public int myplace=0; public int ok=0; public int frame=0; public int MYPLACE=0; public void act() { // Add your action code here. PLACE place = (PLACE) (getWorld().getObjects(PLACE.class).get(0)); if (Greenfoot.isKeyDown("left") && ok==0 && nr==10) {ok=1; move (5); frame++; framing (); } else if (Greenfoot.isKeyDown("right") && ok==1 && nr==10) {ok=0;move(5); frame++; framing ();} if (getY()<=38 && MYPLACE==0) {MYPLACE=place.place; OlimpFinishMessege olimpfinishmessege = new OlimpFinishMessege(); getWorld().addObject(olimpfinishmessege,715,399);} } public void framing () {if (frame%4==1) setImage ("doesthisrun2.png"); else if (frame%4==3) setImage ("doesthisrun3.png"); else setImage ("doesthisrun.png"); }