That is, when I collide the two rivals, the "game over" screen appears
I hope you help me, I would appreciate it!
if(numOfCollision==2) { getWorld().addObject(new GameOver(), getWorld().getWidth()/2, getWorld().getHeight()/2); Greenfoot.stop(); } //And insde the GameOver class, write something like this: setImage(new GreenfootImage("GAMEOVER", 80, Color.WHITE, new Color(0,0,0,50)));
private void caughtBymoto() { if(isTouching(moto.class) || isTouching(crro1.class)) lives--; if(lives<0) endGame(); } public void endGame() { getWorld().addObject(new GameOver(), getWorld().getWidth()/2, getWorld().getHeight()/2); Greenfoot.stop(); }
setImage(new GreenfootImage("GAMEOVER", 80, Color.WHITE, new Color(0,0,0,50)));
public class GameOver { GifImage gifImg = new GifImage("gameover.gif"); public void act { setImage(gifImg.getCurrentImage()); } }
int count=0, frame=2, numOfImg=0; //count is the counter variable //frame is used to set at what interval will the image change from img1 to img2 //to check total num of images public void act() { count++; if(count%frame==0)//after every 2 seconds, the image will be updated { if(numOfImg>10)//to reset the variable inorder to make it a loop numOfImg=0; setImage("GameOver"+numOfImg+".png");//imgName+(imgNumber)+extension numOfImg++; } }
if(Greenfoot.mouseClicked(null)) Greenfoot.setWorld(new MyWorld());