Everything is still a wacky. The ball can still go through the walls and the movements are still a little off.... I never thought a simple maze game would cause so many problems.
public void act() { checkTurns(); move(); } private void checkTurns() { if (Greenfoot.isKeyDown("left")) turn(-5); if (Greenfoot.isKeyDown("right")) turn(5); } public void move() { int d = 0; if (Greenfoot.isKeyDown("up")) d++; if (Greenfoot.isKeyDown("down")) d--; move(3*d); if (!getIntersectingObjects(VWall.class).isEmpty() || !getIntersectingObjects(HWall.class).isEmpty()) move(-3*d); }
public void act() { move(); } public void move() { int dx = 0, dy = 0; if (Greenfoot.isKeyDown("up")) dy--; if (Greenfoot.isKeyDown("down")) dy++; if (Greenfoot.isKeyDown("left")) dx--; if (Greenfoot.isKeyDown("right")) dx++; setLocation(getX()+3*dx, getY()+3*dy); if (getIntersectingObjects(VWall.class).isEmpty() && getIntersectingObjects(HWall.class).isEmpty()) return; setLocation(getX()-3*dx, getY()-3*dy); }
public void move() { int dx = 0, dy = 0; if (Greenfoot.isKeyDown("up")) dy--; if (Greenfoot.isKeyDown("down")) dy++; if (Greenfoot.isKeyDown("left")) dx--; if (Greenfoot.isKeyDown("right")) dx++; if (dx != 0) { setLocation(getX()+dx, getY()); if (!getIntersectingObjects(VWall.class).isEmpty() || !getIntersectingObjects(HWall.class).isEmpty()) setLocation(getX()-dx, getY()); } if (dy != 0) { setLocation(getX(), getY()+dy)); if (!getIntersectingObjects(VWall.class).isEmpty() || !getIntersectingObjects(HWall.class).isEmpty()) setLocation(getX(), getY()-dy); } }