This maze game has been
adapted for school use from a lecture written by Carl Gustafsson.
To make the maze more interesting, we should be collecting diamonds along the
way. But we don't want to let the person move to the next level until they
have collected all the diamonds. Here are two ways we can make sure of
this:
- A door stops the person from getting to the target. When all the
diamonds are gone, the door disappears.
- The target does not appear in the room until all the diamonds are
collected. We do this by placing an invisible target marker object
in the room. When all the diamonds are gone, it destroys itself and
creates a target object in its place.
We will use the first method here:
 |
Add 2 new sprites sprDoor and sprDiamond You can use any
suitable sprites. These are the ones I used: sprDoor: As the rock
is only 24x24 pixels, I stretched it by 135% in the sprite editor to make it fit
the grid better.
sprDiamond: Make sure that
your sprite is a suitable size; you can stretch or scale it in the sprite editor
if you need to.
Add 2 new objects: objDoor and objDiamond. Make the
door solid as it acts like a wall.
|
 |
Sounds
Add sounds for picking up the diamonds and for opening the door. Call them sndDiamond, and sndDoor.
|
 |
Place diamonds around your maze.
The objDiamond should have a collision event with the person.
It should then play the diamond sound and destroy itself. (The
destroy the instance action should be set to self)

|
 |
Place the door so that it blocks access to the target. Don't
put any diamonds on the other side of the door! In the person object, add a collision event with the door object,
stopping the person and aligning it with the grid. (Just the same as you
did with the wall object.)
|
 |
Go back to the door object. When all the diamonds are gone, the door
should play a sound and destroy itself.
 |
| There is an event called a step event.
That event occurs once for every step of the game, which is usually
30 times a second. It is very useful for things that should be
checked often during the game. |
|
Add the step event to the door object. Add the 'If the number of instances is
a value' action. (On the Control tab) Choose these options:

We want to play a sound and destroy the door if there are no
diamonds left, so we need to add block markers to our actions. We need
block markers so that both actions are carried out if the number of
instances is zero.
If you didn't use block markers, the sound would be played
when the diamonds were all gone, but the door would be destroyed in the first
step of the game!

|
| |
Your game should now be ready to play. Save and play your game to test whether it works as expected. |
 |
The Target Marker
Instead of blocking the target with a rock, you could use a
target that does not appear in the room until all the diamonds are
collected. We do this by placing an invisible target marker object
in the room. When all the diamonds are gone, it destroys itself and
creates a target object in its place.
Create a marker sprite and object. Call
them sprMarker and objMarker. Make it invisible by unchecking the Visible option.
Then use the step event and add an action 'If the number of
instances (of the diamond) is zero, Change the Instance to change the
marker to the actual Target object.

Place the target marker in the room where you want the target to
appear.
|
|
Now we will move on to look at scoring.