Game Development Reference
In-Depth Information
Note
For the remainder of this chapter, we're going to take you step-by-step through the
implementation of the other user interface items: the timer, collection counter, health display, and lives
counter. However, they all follow a very similar structure, so feel free to spare your mouse finger and just
read the steps provided before loading
zool15.gmk
at the very end of the chapter.
Adding the Timer Object
1.
Duplicate
obj_score
to create a new object called
obj_time
that uses
spr_icon_time
.
2.
Add a
Create
event and include a
Set Variable
action (
control
tab) that sets
time_allowed
to
200
. We have just hard-coded the default number of seconds to
complete each level, but you could make this a global variable, or even a constant.
3.
Include a
Set Variable
action that sets
time_remaining
to
time_allowed
.
4.
Add a
Step, Step
event and include a
Set Variable
action that sets
time_remaining
to
time_allowed-(global.step_count/room_speed)
. The
room_speed
variable stores the
number of steps in a second for this room (as set in the Room
settings
tab).
5.
Include a
Test Variable
action that tests if
time_remaining
is
smaller than
0
.
6.
Follow this with a
Restart Room
action (
main1
tab).
7.
Select the
Draw
event.
8.
Edit the third
Set Variable
action for
digit
and replace
6
with
3
.
9.
Edit the fourth
Set Variable
action for
text_string
and replace
score
with
time_remaining
.
10.
Edit the first
Draw Sprite
action for
spr_icon_score
and set it to draw
spr_icon_time
at
a
Relative
position of
X
=
230
,
Y
=
280
.
11.
Edit the second
Draw Sprite
action for
spr_icon_digits
and change the position to
X
=
240+(16*digit)
,
Y
=
280
.
12.
Reopen
obj_controller
and include a
Create Instance
action in its
Create
event that
creates an instance of
obj_time
.
Note that
obj_time
actually includes the actions restarting the level when time runs out, so if
you wanted to play the game without the time limit, then you can simply choose not to put
obj_time
in the room.
Next, we consider the collectibles. These items are closely linked with completing each level,
as the exit does not appear until a certain percentage of them have been collected. Exits were
often placed in hard-to-reach positions, so once activated, the interface also provides a kind of
“compass” that points in the direction of the exit.
Search WWH ::
Custom Search