6 Scoring & Lives
Create a new object called obj_game_controller. It will not have a sprite attached to it. Uncheck the Visible box and check the Persistent box. If you cannot see the Persistent box, save your game and click on File, Advanced Mode and try again.
Add a Create Event and drag in a Set Lives icon. Choose a number of lives (eg 5). Then drag in the Score Caption icon from the bottom of the score tab. Fill in the pop-up as follows,
Open up your room window and add the obj_game_controller to the room. Place it anywhere where there isn't already something. Save your game and test it quickly to see if the score and lives are being shown in the window bar.
Go back to the obj_game_controller window and add a No More Lives Event (other).
Drag in the Sleep icon and set the timer for 1000 milliseconds.
Drag in the Display Message icon and set the message to Game Over.
Drag in the End Game icon.
Save and test that the game indeed ends when you run out of lives.
You may have noticed that this is not a particularly elegant way to end the game. You might want to come back and tidy this up later.
You also want to do something when the player runs out of ghosts to hit. The easiest thing to do is restart the room and that is what we'll do.
Add a Step Event. At the start of each step, we'll check to see if there any ghosts left.
Drag in the Test Instance Count icon.
Drag in a Start Block icon and then the Restart Room icon. Finish with an End Block icon like the screenshot.