I have copied my code exactly and I do not understand why the gameover text only appears after the game has ended (Greenfoot.stop()), I initially just get the greenfoot logo in its place. For the gameover to then appear, I have to click on Act one more time to force it to move on before it will appear.
Can anyone help?
This is the code from my Rocket class. Gameover is another Actor.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Rocket here.
*
* @author (your name)
* @version (a version number or a date)
*/
//This class defines a fish. Fish live in the sea.
public class Rocket extends Transport
{
/**
* Act - do whatever the Rocket wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(isAtEdge())
{
turn(60);
}
if(Greenfoot.isKeyDown("up"))
{
turn(4);
}
if(Greenfoot.isKeyDown("down"))
{
turn(-4);
}
Actor Cargo;
Cargo = getOneObjectAtOffset(0, 0, Cargo.class);
if (Cargo != null)
{
World world;
world = getWorld();
Space space = (Space)world;
//add the counter from Space to counter here
Counter counter = space.getCounter();
//now you can apply the method addScore() to the counter from
//space to add 1 to the score
counter.addScore();
world.removeObject(Cargo);
}
Actor Asteroid;
Asteroid = getOneObjectAtOffset(0, 0, Asteroid.class);
GreenfootImage explosion = new GreenfootImage("explosion.png");
if (Asteroid != null)
{
World world = getWorld();
//Gamover is appearing only after Greenfoot.stop()...
Gameover gameover = new Gameover();
setImage(explosion);
world.addObject(gameover, world.getWidth()/2, world.getHeight()/2);
Greenfoot.stop();
}
else if (Asteroid == null)
{
move(4);
}
}
}
