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

2022/5/10

I need help, to put a "Game over" screen or an animation that says game over in greenfoot

1
2
3
4
MR.UWU MR.UWU

2022/5/10

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

2022/5/10

#
hola
Roshan123 Roshan123

2022/5/10

#
MR.UWU wrote...
when I collide the two rivals
Should it pop-up when the object collides simultaneously with the 2 rivals or one after another(seperately)?
Roshan123 Roshan123

2022/5/10

#
If its seperately, then create a counter variable which instantly checks the collision and update the variable when it touches the 1st rival and same goes for the 2nd rival. After the 2nd collision, you may write something like this:
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)));
MR.UWU MR.UWU

2022/5/10

#
private void caughtBymoto() { if(isTouching(moto.class)) { lives--; if(lives<0) { endGame(); } } if(isTouching(crro1.class)) { lives--; if(lives<0) { endGame(); } } there are the two rivals (separately), but they are the same code, each one works individually, and I want to see if it works in that code
Roshan123 Roshan123

2022/5/10

#
Hope it works all fine!
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();
}
Create a GameOver class and then write.....
setImage(new GreenfootImage("GAMEOVER", 80, Color.WHITE, new Color(0,0,0,50)));
MR.UWU MR.UWU

2022/5/10

#
ok
MR.UWU MR.UWU

2022/5/10

#
hey it worked for me I wanted to ask how I could put a gif I know it's with a library but I don't know the code
Roshan123 Roshan123

2022/5/10

#
MR.UWU wrote...
hey it worked for me I wanted to ask how I could put a gif I know it's with a library but I don't know the code
Here it goes
public class GameOver
{
  GifImage gifImg = new GifImage("gameover.gif");
  public void act
  {
     setImage(gifImg.getCurrentImage());
  }
}
MR.UWU MR.UWU

2022/5/10

#
it works for me but the gif is not shown
MR.UWU MR.UWU

2022/5/10

#
I mean the animation is not seen
MR.UWU MR.UWU

2022/5/10

#
hola
MR.UWU MR.UWU

2022/5/10

#
Does anyone know how when I click on my world, it restarts, not by clicking reset, but rather by clicking on the world?
Roshan123 Roshan123

2022/5/11

#
MR.UWU wrote...
it works for me but the gif is not shown
An alternative way: 1st take consecutive screenshot of that gif and rename each and every pic from img0 to imgX (Here X is the total number of screenshot)
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++;
  }
}
Roshan123 Roshan123

2022/5/11

#
MR.UWU wrote...
Does anyone know how when I click on my world, it restarts, not by clicking reset, but rather by clicking on the world?
Provide the source code or check whether you have written something similar to this
if(Greenfoot.mouseClicked(null))
Greenfoot.setWorld(new MyWorld());
There are more replies on the next page.
1
2
3
4