Game Development Reference
In-Depth Information
Traps and Puzzles
So now that we know more about the plan for the level, it's time we started implementing some
of the features. The puzzle elements of the game are all simple interactive behaviors of the kind
that you should be very familiar with by now. You can summarize nearly all of these behaviors as
a collision event between two instances that changes the state of an instance. One of the colliding
instances is nearly always Flynn or Archie and the instance that changes state could be either of
the colliding objects, or a third object that is not involved in the collision. The best way to see this
is to see some examples, so we have created a version of the game that contains all the puzzles for
this level in the file shadows7.gmk in the Chapter13/Games directory on the CD. In this section, we'll
discuss some of the less familiar concepts that we've used to make the traps and puzzles work,
but first take a look at the game.
Play it now. You should be able to complete it fairly easily with the information from the
walkthrough, but it's pretty hard without restart points. We'll address that later, but now that
you've seen what the level has to offer, we can take a closer look at how some of these traps and
puzzles have been implemented so that you could add more if you wanted to.
Traps
We've chosen to include a few simple traps in this level because we wanted to show you how to
implement them for yourself. Take a look at the barrel trap as an example ( obj_barrel in the
Hazards group). All of the traps use a single object called obj_trap as their parent and have a
variable called activated to determine when they should trigger. This is initially set to false in
their Create events, but can be set by any object in an appropriate event (often a Collision event)
by using the following code.
var trap;
trap = instance_nearest( x, y, obj_trap );
trap.activated = true;
We've created a new kind of lift object called obj_lift_trigger to trigger the barrel traps.
You'll find this code in the Step event of obj_lift_trigger to activate nearby traps. Using the
instance_nearest function in this way means that we don't need to hard-code exactly which
object triggers which trap and any object can do the job for any trap, provided they are positioned
near to one another on the level.
The barrel trap is triggered by the lift trigger platform when Flynn is above but not
overlapping the platform. The barrel is initially created with gravity turned off, but setting the
activated variable turns gravity on and lets it fall down the slope toward the player. The trigger
lift turns into a falling lift ( obj_lift_fall ) until it hits something and then back into a “normal”
static lift again ( obj_lift ). All this means that the lift trigger is only a single use trigger, but the
barrel actually resets itself after a couple of bounces so that it could be triggered again.
Another example of this on the level is the spear trap. This uses an identical mechanism to
trigger the nearest trap, but both the trigger ( obj_tripwire ) and trap ( obj_spears ) reset
themselves after a period of time so that they can be used again. Using this system, you could just
as easily set up a lift trigger to set off some spears of a tripwire to set off the barrel.
The file traps.psd in the Chapter10/Traps directory contains a range of artwork for different
traps that you could include in the game. Using this system, you can make sure that they are all
interchangeable to keep the player (quite literally) on their toes.
 
Search WWH ::




Custom Search