Game Development Reference
In-Depth Information
Prisoner Cages
The main puzzles in this level revolve around the prisoner cages that need to be unlocked by
using Archie to retrieve a key and take it to the lock. We've implemented the behavior of the
prisoner cages using three component objects that you'll find the Misc and NPCs groups: a ship's
wheel ( obj_wheel ), a cage ( obj_cage ), and a counterweight ( obj_counterweight ). The ship's wheel
acts much like a trap trigger, finding the nearest cage and activating it after a collision with an
instance of obj_parrot . However, the wheel is supposed to be locked so this Collision event
makes sure that Archie is holding a key before activating the cage.
Like the traps, the cage object has an activated variable that makes it fall to the ground and
release the prisoner. The level is designed to make sure this happens off-screen, so that we don't
need additional collision animations for the prisoner or cage. In fact, the prisoner is part of the
cage object and is drawn within its Draw event. The prisoner sprite drawn depends on the value
of the prisoner variable, with a value of 1 drawing the young prisoner and a value of 2 drawing the
older one. However, you won't see this variable set in the cage's Create event, as this would result
in the same prisoner for every cage. Instead, it is set within Creation Code , which is specific to
each instance.
You can set Creation Code within the Room Editor by right-clicking on an instance with the
Control key held down and selecting Creation Code from the menu. This opens up the code
editor so that you can add code that just needs to be executed for that instance (see Figure 13-7).
We've simply put the line prisoner = 1 (or 2) into this Creation Code depending on the prisoner
required in each position in the room.
Figure 13-7. Using the Creation Code option in the Room Editor.
The counterweight object is the final object that makes up the cage behavior. It is basically
just a lift platform that looks for the nearest cage and moves in the opposite direction to it. This
makes the counterweight move up when the cage moves down and vice versa. Both the cage and
the counterweight use the same chain drawing routines as the lift platforms, so that the length of
the chains is handled automatically. Together, these create a convincing-looking pulley system
for making the cages work.
 
Search WWH ::




Custom Search