Just Rewards: Collecting Diamonds, Unlocking Doors

Many maze games involve the collection of point scoring treasure. In our maze, we shall require the player character to collect diamonds, and receive points in exchange for them.

Create a diamond sprite (use the diamond.gif image in the Resources folder) and use it to depict a diamond object (obj_diamond).

Now think about what you want to happen when the player collides with the diamond. I can think of two essential actions and at least one nice-to-have.

What actions do you think are required? [Think about it… ;-)]

When the player character collides with a diamond, we need to increment the player’s score, and make the diamond disappear. I think it would also be nice to provide an audible reward when a diamond is collected, by playing a sound.

The simplest way of adding these actions is to create a collision event for the diamond object that detects a collision by the player object, and then:

  • increments the score;
  • plays a sound (remember – you’ll need to add one to the library first!)
  • and then destroys the current (self) diamond object instance (so we can’t keep collecting the same diamond again and again, ad infinitum, and racking up a very high, if tediously achieved, high score!).

Alternatively, you could set a single action for the collision event that destroys the diamond object instance, and then use a Destroy event within the diamond object to trigger the score and sound actions.

Try adding some instances of diamonds to at least one of the rooms. Does the opportunity to collect treasure affect the way that you guide your player character through the room?

If you have any monsters in the room, try to arrange the position of some of them so that they guard a particular diamond. Is it possible to position the monsters in such a way that it makes it impossible for the player character to acquire a particular diamond? If so, how do you think this will make the player feel?

Can you position the monsters so that some diamonds are more difficult to reach than others?

If some diamonds are guarded by monsters in such a way that the player character feels that there are quite likely to risk losing a life collecting a particular diamond, they may decide to forgo it and not even attempt to collect it. How could you motivate – or even compel – the player to try to collect all the treasure items in the room, or at least a certain minimum number of them?

Blocking progress to the next level until a challenge is completed

A common theme in many early maze games was to block the player from exiting the room and moving onto the next one until all the treasure items had been collected. One widely used metaphor was to provide a “locked door” that barred the way to the next level and that could only be opened by the player collecting all the treasure items. (Alternatively, the player might have to collect a single magic key from somewhere within the level in order to open the door.)

Write down a brief specification of what objects, sprites, events and actions actions you think you need in order to implement a locked door that blocks access to the way out of a room, and that can only be opened (destroyed?) once you have collected all the diamonds in the room.

Here’s one way of approaching the problem: “every time the player collides with a diamond, after destroying the diamond object (an action that is executed when the ‘Collide with player’ event is within the diamond object) test to see whether the count the of the number of instances of the diamond object is zero; if it is, destroy the door”.

  • create a new door sprite (spr_door) by copying the wall sprite, and changing the colour (refer back to Editing a Sprite if you can’t remember how to do this); add the door to the maze so that it blocks access to the exit;

  • copy the wall object to create a new door object (obj_door) and use the door sprite to represent it;

  • add a Test Instance Count action from the Questions panel of the control tab, and configure its properties so that it will test whether the number of instances of the diamond object is equal to zero; as the very next action (the action that will be performed if the diamond instance count is zero) use a Destroy event from the Objects panel of the main1 tab configured to destroy instances of the object obj_door.

The first Destroy action should destroy the “self” diamond object instance. The second Destroy action – which is executed if the previous conditional statement evaluates as true (that is, if there are zero instances of the diamond object) should apply to the door object:

You might also find that the experience of the game is improved if you give an audible signal to the player when the goal of unlocking the door has been achieved.

Try running your program. Does the door disappear when you have collected all the diamond objects? What would happen if you had several door instances in the room?

How do you think you might extend the game further so that a locked iron door barring the way out of the room can only be unlocked by collecting a rare ‘red diamond’ placed somewhere within the room? Suppose further that access to the red diamond is blocked by a different sort of door that can only be opened by collecting at least three ‘ordinary’ diamonds.

Achieving the same thing, but differently…

One of the attractive features of Game Maker (depending on your point of view!) is that there are often several ways of achieving the same thing. In the previous section, we used the player collision event within the diamond object to open the door when the diamond count in the room hit zero. Alternatively, we could have used an action within the door object to achieve the same thing. In this case however, we would apply the destroy action to the self object if the diamond count equalled zero. In order to test the diamond count regularly, we would need to place it within a Step event in the door object.

To understand how the Step event works, you need to understand a little about how Game Maker operates when a game is played. Essentially, many times a second, Game Maker looks in turn at each instance of each object within the current room, testing each event as it does so. If the event is true, then the actions for that event are performed.

The Step event is simply an event that says ‘each time you test me, then perform the actions associated with me’. In this way, every time Game Maker ‘looks’ at the state of the door object, it will run the actions performed with the step event, and test how many instances there are of the diamiond object in the room…


0 Responses to “Just Rewards: Collecting Diamonds, Unlocking Doors”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s



%d bloggers like this: