That is, when I collide the two rivals, the "game over" screen appears
I hope you help me, I would appreciate it!


1 2 3 4 5 6 7 8 | 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 ))); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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(); } |
1 | setImage( new GreenfootImage( "GAMEOVER" , 80 , Color.WHITE, new Color( 0 , 0 , 0 , 50 ))); |
1 2 3 4 5 6 7 8 | public class GameOver { GifImage gifImg = new GifImage( "gameover.gif" ); public void act { setImage(gifImg.getCurrentImage()); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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++; } } |
1 2 | if (Greenfoot.mouseClicked( null )) Greenfoot.setWorld( new MyWorld()); |