Game Development Reference
In-Depth Information
Lines 14-25 are new. Line 14 looks for an instance of
obj_box
in the direction of
the grid square where
obj_player
would walk into if it started to move. The instance ID
of this box is placed in the variable
box
. The
with
statement in line 15 then executes the
code in lines 16-25 within the context of the found box. In other words, what happens
in that script happens inside the found instance of
obj_box
and not in
obj_explorer
.
Note that if no instance of
obj_box
was found in that direction, this code is not
executed at all!
The code executed for the found box first checks, in turn, if there is an impassable
object (wall or box) in the direction where we're trying to move it (line 17). If this is the
case, it sets the speed of
obj_explorer
to
0
. It's important to realize here that within a
with
statement, the keyword
other
refers to the instance calling the
with
statement.
If there is no box or wall in the way, lines 21-22 give the box the same horizontal or
vertical speed as the explorer. So rather than pushing the box, we let it move on its own
accord. That's why we also set alarm 0 in line 23 relative to the speed and the size of
the grid. We'll make it deal with stopping the box next.
Double-click
obj_box
again and add an
Alarm
,
Alarm 0
event. Insert the
Set Variable
action with
Variable
speed
and
Value
0
. This makes sure the speed is set to zero again
once the alarm reaches zero.
5.
Finally, place a few instances of
obj_box
in the test room and start pushing them
around to see if it works.
6.
Result:
Reference/Result/pushing_boxes.gmk
Scrolling Text (Horizontal)
We call it scrolling text, but news channels call it a
ticker tape
: a line of text that scrolls slowly from
right to left, usually at the bottom of the screen. In a game, it's great for showing credits.
Start with:
Reference/Framework/space1.gmk
Creating the Horizontally Scrolling Text
1.
Create a new font for the ticker tape and give it the name
fnt_tickertape
. Select
Verdana for the
Font
and set the
Size
to
24
.
2.
Create an object and give it the name
obj_tickertape
. Set the
Depth
to
-1000
.
3.
Add a
Create
event and include an
Execute Code
action. Insert the following lines:
1:
{
2:
ticker = "The Game Maker's Companion was written by Jacob ";
3:
ticker += "Habgood, Nana Nielsen and Martin Rijks, with ";
4:
ticker += "artwork by Kevin Crossley. This is an example ";
5:
ticker += "text for a ticker tape. It will wrap once it has ";
6:
ticker += "disappeared from the screen..."
7:
x = room_width;
8:
hspeed = -4;
9:
}
Search WWH ::
Custom Search