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

2015/4/6

Ending game when falling in pit

Rass Rass

2015/4/6

#
I am developing a platformer for a college course and I am trying to figure out how I would stop the game if the player was to fall into a pit. If anyone has any tips, I'd very much appreciate it! (I will post code if I get a reply, my player class is simply called Player and the pit class is under Actor and is called Death)
danpost danpost

2015/4/6

#
So, do you want the game to stop when the Player object touches the Pit object? or is it more than that -- and, if so, what?
Rass Rass

2015/4/6

#
Yeah, I would just like the game to stop when player touches the pit.
danpost danpost

2015/4/6

#
Rass wrote...
Yeah, I would just like the game to stop when player touches the pit.
In the act method of either class, put an 'if' statement using the 'isTouching' boolean method to stop the game with:
1
2
3
4
// in Player class
if (isTouching(Pit.class)) Greenfoot.stop();
// or in Pit class
if (isTouching(Player.class)) Greenfoot.stop();
Either one will work (looks pretty much like the way you just phrased it, huh!). Looking through the API documentation of classes will give you an idea of how to phrase things so that the coding becomes easier.
Rass Rass

2015/4/6

#
Thank you very much, danpost. The code is working, if any problems occur, I will post again. Thanks very much!
You need to login to post a reply.