Game Development Reference
In-Depth Information
4.
Create an object
obj_compass
and set the
Sprite
to
spr_compass
. For each room, this
object will store what the rooms are when going in northern, southern, eastern, and
western directions. We don't want it to actually be visible, so unmark the
Visible
check
box.
5.
Now open
obj_explorer
again and add an
Other
,
Intersect Boundary
event. This event
occurs when the instances cross the boundary (limits) of the room. We use this event
rather than the
Outside Room
event simply because we wish to keep the explorer on
the screen at all times. Include the
Execute code
action and insert the following lines:
1:
{
2:
transition_steps = 30;
3:
if ( x <= 0 )
4:
{
5:
x += room_width-sprite_width;
6:
transition_kind = 14;
7:
room_goto(obj_compass.west);
8:
}
9:
if ( x >= room_width-sprite_width )
10:
{
11:
x -= room_width-sprite_width;
12:
transition_kind = 15;
13:
room_goto(obj_compass.east);
14:
}
15:
if ( y <= 0 )
16:
{
17:
y += room_height-sprite_height;
18:
transition_kind = 16;
19:
room_goto(obj_compass.north);
20:
}
21:
if ( y >= room_height-sprite_height )
22:
{
23:
y -= room_height-sprite_height;
24:
transition_kind = 17;
25:
room_goto(obj_compass.south);
26:
}
27:
}
Don't worry—room movement doesn't get more complex than this script. To
understand it, imagine that the explorer is standing near a western exit. If the explorer
continues to move left, we want the screen to quickly pan to the next room and have
the explorer appear on the right-hand side of the new room at the same height he left
the previous room. This is essentially what this script does for all directions, and it's
using a room transition to create the panning movement.
Search WWH ::
Custom Search