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

2014/12/31

stop certain classes for game over screen

Steven.Z. Steven.Z.

2014/12/31

#
hi when the actor of my game dies, a game over font appears in the middle of the screen and the enemies are still moving; i want some of them to stop moving as soon as the game over appears; how can i do that? thats the code for the game over
1
2
3
4
5
6
7
8
public class GameOver extends Actor
{
   public GameOver()
   {
       setImage("GAME OVER.png");
       Greenfoot.playSound("GameOver.mp3");
   }
}
thanks
danpost danpost

2014/12/31

#
Let us see ... your options are: (a) remove those actor you do not want moving (or all objects) from the world (b) have them only act if no GameOver class object is in the world (c) create and set an entirely new world active for the game over message (which essentially removes all game objects from view) if using (a) or (b), the main actor will probably need to be dealt with also; otherwise, you may be creating multiple GameOver actors, one on top of another.
Greg.Hutchinson Greg.Hutchinson

2014/12/31

#
I think adding this to the code will also work.
1
2
3
4
5
6
7
8
9
public class GameOver extends Actor
{
   public GameOver()
   {
      setImage("GAME OVER.png");
      Greenfoot.playSound("GameOver.mp3");
      Greenfoot.stop();
   }
}
Greg.Hutchinson Greg.Hutchinson

2014/12/31

#
Oops - Sorry - I just reread your question more closely. My code will stop all actors from moving. Danpost ideas are better.
Steven.Z. Steven.Z.

2015/1/1

#
thanks for your answers i think dans solution b would be the best i still want them in the world but just stopped or paused which commands would i have to use for that? i already had the green foot.stop or delay method, but that would stop everything could it be like this?
1
2
3
4
5
6
7
public void stopCertainClass()
{
if(gameover)
{
stop(CertainClass.class)
}
}
danpost danpost

2015/1/1

#
You should not have to add extra methods into your classes for stopping the certain ones. Just do not have the code in the act methods of those you wish to stop execute when the game is over.
1
2
3
4
5
6
7
8
9
10
11
// currently
public void act()
{
    // your code
}
// revised for stopping
public void act()
{
    if ( ! getWorld().getObjects(GameOver.class).isEmpty() ) return;
    // your code
}
Steven.Z. Steven.Z.

2015/1/1

#
thanks a lot, that worked very well! i have one more question: i have one class that needs to stop after a certain time, so how should i change this code to stop after timer == 1000?
danpost danpost

2015/1/1

#
What have you tried?
Steven.Z. Steven.Z.

2015/1/2

#
1
2
3
4
5
6
7
public void moveLeft()
{
if(! timer == 1000)
{
setLocation (getX()-2, getY());
}
}
so its just supposed to move left until the gamer has run out and reached 1000
Steven.Z. Steven.Z.

2015/1/2

#
i already solved the problem, thanks, but unfortunately a new one came up: i want that the score counter remembers the points from the last level and not always starts from 0; i found here a solution for a similar problem but it just didn't work, i don't know why.
1
2
3
public class Level1 extends World
{
Counter counter = new Counter();
thats for the first level and for now i copied it into level 2 but right now it always starts from 0; so do i need to generate a new class of counter for level 2; until now it didn't work the way i wanted to
danpost danpost

2015/1/2

#
See how I accomplished it with my Super Level Support Class.
chandan03 chandan03

2015/4/10

#
i want to set a score , when actor achieve this score, game will over and it will show actor win. how can i do this ?
danpost danpost

2015/4/10

#
@chandan03, please do not revive old discussion thread with new issues. Start a new one and please include relevant codes and information with regards to your project.
You need to login to post a reply.