This site requires JavaScript, please enable it in your browser!
Greenfoot back
NAMYA0303
NAMYA0303 wrote ...

2016/8/26

how to add a game over screen (my actor dies when touches the edge)

NAMYA0303 NAMYA0303

2016/8/26

#
guys an anyone help me with this i have made my game over characters the code of GameOver character-
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class GameOver here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GameOver extends Actor
{
    /**
     * Act - do whatever the GameOver wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
   public GameOver()
   {
       setImage(new GreenfootImage("Game Over", 48, Color.RED, Color.BLUE));
   }
}
danpost danpost

2016/8/26

#
Alter the code given by Super_Hippo to this:
if (isAtEdge())
{
    Greenfoot.stop();
    World world = getWorld();
    addObject(new GameOver(), world.getWidth()/2, world.getHeight()/2);
    world.removeObject(this);
}
NAMYA0303 NAMYA0303

2016/8/27

#
i just copied ur code and pasted but its showing a red line under "addObject"
/**
     * 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() 
    {
        // Add your action code here.
         moveAndTurn();
        eat();
        if (isAtEdge()) getWorld().removeObject(this);
        if (isAtEdge())
       {
       Greenfoot.stop();
       World world = getWorld();
       addObject(new GameOver(), world.getWidth()/2, world.getHeight()/2);
       world.removeObject(this);
      }
    }     
danpost danpost

2016/8/27

#
NAMYA0303 wrote...
i just copied ur code and pasted but its showing a red line under "addObject"
It should be 'world.addObject( ...'. Thanks. @NAMYA0303, you will need to remove line 10 from what you gave above.
NAMYA0303 NAMYA0303

2016/8/27

#
thanks alot!!!!! u helped me with this game (: (: (; (; thnxxxxxxxxxxxxxxxxxx
You need to login to post a reply.