Level 2 - Collecting Objects
The goal of this level is to collect objects (i.e. diamonds) . The collecting itself is easy. But how do we make sure the player cannot exit the room when not all diamonds are collected? To this end we add a door object. The door object will behave like a wall as long as there are still diamonds left, and will disappear when all diamonds have gone.
Beside the wall, goal, and person object we need two more objects, with corresponding sprites: the diamond and the door. The diamond is an extremely simple object. The only action it needs is that it is destroyed when the person collides with it. So in the collision event we put an action to delete it.

The door object will be placed at a crucial place to block the passage to the goal. It will be solid (to block the person from passing it). In the collision event of the person with the door we must stop the motion. In the step event of the door we check whether the number of diamonds is 0 and, if so, destroys itself. There is an action for this. We will also play some sound such that the player will hear that the door is opened. So the step event looks as follows:

Score
For each diamond destroyed we give 5 points. So in the destroy event of the diamond we add 5 points to the score. Finishing a level gives 40 points so we add 40 points to the score in the collision event for the goal with the person.
When the player reaches the last room a high-score table must be shown. This is easy in Game Maker because there is an action for this. The goal object does become a bit more complicated though. When it collides with the person the following event is executed:

It adds something to the score, plays a sound, waits a while and then either goes to the next room of, if this is the last room, shows a message, the high-score table, and restarts the game.
Note that the score is automatically displayed in the caption. This is though a bit ugly. Instead we will create a controller object. It does not need a sprite. This object will be placed in all rooms. It does some global control of what is happening. For the moment we just use it to display the score. In its drawing event we set the font and color and then use the action to draw the score.

Starting screen
It is nice to start with a screen that shows the name of the game. For this we use the first room. We create a background resource with a nice picture. This background we use for the first room . A start controller object (invisible of course) is created that simply waits until the user presses a key and then moves to the next room. (The start controller also sets the score to 0 and makes sure that the score is not shown in the caption.)
Sounds
A game without sounds is pretty boring. So we need some sounds. First of all we need background music. For this we use some nice midi file. We start this piece of music in the start_controller, looping it forever. Next we need some sound effects for picking up a diamond, for the door to open, and for reaching the goal. These sounds are called in the appropriate events described above. When reaching the goal, after the goal sound, it is good to put a little sleep action to have a bit of a delay before going to the next room.
Creating rooms
Now we can create some rooms with diamonds. Note that the first maze room without diamonds we can simply leave in. This is good because it first introduces the player to the notion of moving to the flag, before it has to deal with collecting diamonds. By giving a suggestive name to the second room with the diamonds, the player will understand what to do.