Now things will start to get interesting. No longer will Pacman be invincible, although if we're testing other aspects of the game you can still make him invincible. What we'll do here is make Pacman die if he collides with a ghost that is not in FREIGHT or SPAWN mode. That means a few things.
Once this section is finished then we'll have more or less a complete game. Just not a very good looking one. We'll take care of that later, but for now lets kill Pacman.
We'll start by giving Pacman 5 lives. That seems like a good number.
When Pacman dies we don't want to start the level over or anything, we just need to reset his position and a few other variables. We'll also want to reset the ghosts, so let's create a basic reset method in the Entity class. Good thing we still have a reference to the start node right? We just place them back there.
For Pacman, however, we'll need to do a bit more to reset him. So let's override the basic reset method from the Entity class and add a couple more things. We need to set Pacman's initial direction to LEFT and place him between the 2 nodes discussed previously.
Similar to Pacman we'll override the Entities reset method and just add a couple things. We need to reset the points to 200 and the direction back to the goalDirection in case it's something else when Pacman dies. I guess it can't be anything else at this point, but including it won't hurt.
Finally, in the checkGhostEvents method when we detect that Pacman has collided with a ghost, if the ghost is not in FREIGHT mode we check to see if it is in SPAWN mode. If it is then we can safely ignore, but if not we need to kill Pacman.
So we reduce his number of lives by 1 then we check to see if he has any more lives left. If not then we restart the game. If he has lives left then we just reset the game. In both cases we'll pause for 3 seconds before calling the respective methods.
We need to make sure that we can't pause the game while Pacman is dying. Pacman takes a few seconds to die, so right now it would be possible to pause the game while he is dying and then there would be no way to advance to the next level with the way things are. So we'll add this check to make sure we can only pause the game while Pacman is alive.
Well, that's pretty good so far right? We pretty much have a full game on our hands now. We have a starting point and ways to win and lose. It just doesn't look very good. I think it's time to add some pizzaz!