What code should I useif i just want to display a game over image at the end of the game
import Greenfoot.*;
import java.awt.Color;
public class GameOver extends Actor
{
String msgTxt;
World world;
public GameOver(World w)
{
this("GAME OVER", w);
}
public GameOver(String txt, World w)
{
msgTxt = txt;
world = w;
updateImage();
}
private void updateImage()
{
GreenfootImage image = new GreenfootImage(world.getWidth(), world.getHeight()); // or whatever size you want the object
image.setColor(Color.cyan); // color of your choice
image.fill();
GreenfootImage txtImg = new GreenfootImage(msgTxt, 36, Color.black, new Color(0, 0, 0, 0)); // colors and font size of your choice
image.drawImage(txtImg, (image.getWidth() - txtImg.getWidth()) / 2, (image.getHeight() - txtImg.getHeight) / 2);
// whatever else you might want to do for the image
setImage(image);
}
}addObject(new GameOver(this), getWidth() / 2, getHeight() / 2);
// above for center screen (you can adjust location, if you desire)
// or
// for something other than 'GAME OVER' as text
addObject(new GameOver("YOU WIN", this), getWidth() / 2, getHeight() / 2); if (getX() == 30 && getY() == 19)
{
List getSCORE = getWorld(). getObjects (SCORE.class);
if (!getSCORE.isEmpty())
{
SCORE currScore= (SCORE) getSCORE.get(0);
currScore.updateScore(20);
}
{
addObject(new LevelComplete.class(),10,10);
}
Greenfoot.stop();
}