Game Development Reference
In-Depth Information
Line 2 first sets up the speed for the room transition, which we want to be the
same for all directions. We make it equal to the room speed ( 30 ), which means the
transition we select will take exactly one second. Line 3 checks if the explorer is leaving
from the left end of the screen. If so, line 5 resets the x position by adding the room
width minus the sprite's width—this places the obj_explorer at the entrance in the
new room. Remember, obj_explorer is persistent, so it will be going to the new room
while preserving its x and y position and that's why we need to change them.
Line 6 sets the transition_kind . This is a Game Maker system variable with which
you can set what transition to use when changing rooms. A value of 14 means Push
from left , making the room we go to push the current room away from the left. Line 7
tells Game Maker to jump to the room stored by obj_compass.west . The variable west is
a local variable of obj_compass that we'll set up later.
Lines 9-14 do the same thing, but now we check if obj_explorer is leaving on the
right-hand side of the room. Note that because the sprite's origin is in the top-left
corner of the sprite, the sprite may already be overlapping the eastern boundary—
that's why we subtract its width in the comparison in line 9. Line 11 is simply the
opposite of line 5, making sure the x position of the explorer is reset to the left-hand
side of the room. Line 12 sets the transition to 15 ( Push from right) and line 13 jumps to
the room stored in the variable obj_compass.east .
In the same way, lines 15-19 deal with movement in upward (northward)
direction using a Push from top transition and lines 21-26 deal with movement in a
downward (southward) direction using a Push from bottom transition.
We're done with the logic! The next step is to place a compass object in each room and tell it
where the exits lead. This is where our map a few pages back comes in handy, because it will help
us to quickly look up which exit leads where.
Setting Up the Map
1. Open room_1 and place an instance of obj_compass in the room. This object will be
invisible during the game so it doesn't matter where you put it—just put it somewhere
where it won't bother you when adding other instances. Make sure you put only one
instance of obj_compass in the room.
2. If you take a look at the map, you'll see that for room 1, north leads to room 3, east to
room 2, and south to room 4. There is no westward exit. Hold the Control key, right-
click the obj_compass instance, and select Creation Code… from the context menu. By
setting a creation code for an instance, you give it a custom script that is only executed
for that instance in that particular room. We use this feature to set the directions in
each room. Insert the following lines:
1: {
2: north = room_3;
3: east = room_2;
4: south = room_4;
5: }
These variables will be used by obj_explorer once the Intersect Boundary event is
executed to know which room to go to.
3.
There is always the chance that we're going to add or remove instances in a room, so
we might as well lock this instance to save it from accidentally being deleted. Hold the
Control key, right-click the instance again and select Locked .
 
Search WWH ::




Custom Search