Hi all,
I made a game with a menu, and everytime an particular moving object hits the end of the map (The right side) you will die. I made a Gameover screen and obviously I want to make a the objects stop in the background when the Gameover screen is there. I used the Greenfoot.stop(); method for that, and it works, but the problem is, when I click on the 'Back to the Menu' button under the Gameover screen, it does nothing? When I click the 'Back to menu' while the player is still alive and playing it works well.
I know it does have something to withGreenfoot.stop();. I tried to make the objects stop with other ways but it doesn't work like I want to. Do you guys have any simple ways to do this? This is the all code for the object, but the part it it really about is the if (getX() == 799) { part offcourse, thanks.
public class Enemy extends Actor { private boolean beingDragged; private boolean atTargetLocation; public void act() { if (atTargetLocation) return; if (getX() == 799) { Greenfoot.stop(); World myWorld = getWorld(); GameOver gameover = new GameOver(); myWorld.addObject(gameover, myWorld.getWidth()/2, myWorld.getHeight()/2); } if (!beingDragged) { move(1); if (Greenfoot.mousePressed(this)) beingDragged = true; } else { if (Greenfoot.mouseDragged(this)) { MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse != null) setLocation(mouse.getX(), mouse.getY()); } if (Greenfoot.mouseClicked(this) || Greenfoot.mouseDragEnded(this)) { beingDragged = false; seeLocation(); World myWorld = getWorld(); CarWorld carworld = (CarWorld)myWorld; Counter counter = carworld.getCounter(); counter.addScore(); } } } private void seeLocation() { atTargetLocation = ( getX() >= 370 && getX() <= 400 && getY() >= 0 && getY() <= 50 ) || ( getX() >= 370 && getX() <= 410 && getY() >= 550 && getY() <= 600 ) || ( getX() >= 560 && getX() <= 600 && getY() >= 0 && getY() <= 50 ) || ( getX() >= 560 && getX() <= 600 && getY() >= 550 && getY() <= 600 ) || ( getX() >= 700 && getX() <= 745 && getY() >= 0 && getY() <= 50 ) || ( getX() >= 700 && getX() <= 745 && getY() >= 550 && getY() <= 600 ); } }