Game Development Reference
In-Depth Information
Countdown Clock
One simple way to increase the intensity of a game is to force the player to finish a task in a given
amount of time. In our click-the-ball game, we'll display a digital clock, set the timer, and make it
count down to zero. Once time runs out, a message appears and the game ends.
Start with:
Reference/Framework/bouncing1.gmk
Creating the Countdown Clock
1.
Create a font for the digital clock and give it the name
fnt_countdown
. Set the
Font
to
Courier New
, the
Size
to
16
, and make it
Bold
. Set the
Character Range
to
48
Till
58
. As
you may know, computers represent characters using numbers internally. The
numbers tell Game Maker which characters from the font we wish to use. The
numbers come from the
American Standard Code for Information Exchange
(ASCII for
short). You can look up the characters by value in a so-called ASCII table. For now, it is
enough to know that characters 48 to 58 represent the characters for the numbers 0-9
and the colon, which we'll use in the time presentation.
2.
Create an object and give it the name
obj_countdown
. Set the
Depth
to
-1000
. We want
the clock to always appear in front of everything else.
3.
Add a
Create
event and include the
Set Alarm
action. For
Alarm 0
, set the
Number of
steps
to
90*room_speed
. The room speed decides the amount of steps in a second, so
this sets the alarm to 90 seconds.
4.
Add an
Alarm 0
event and add the
Display Message
action. Set the
Message
text to
Time is up!
5.
In the same event, include an
End Game
action.
6.
Add a
Draw
event and include the
Execute Code
action. Insert the following lines:
1:
{
2:
var time, min, sec;
3:
time = round(alarm[0]/room_speed);
4:
min = string(time div 60);
5:
sec = string(time mod 60);
6:
if ( string_length(sec) < 2 ) sec = '0'+sec;
7:
draw_set_font(fnt_countdown);
8:
draw_set_color(c_black);
9:
draw_set_halign(fa_center);
10:
draw_text(320,32,min+':'+sec);
11:
}
We're using the alarm to keep track of the time, but we need to convert the steps into a
readable time format and that's what this script is all about.
Search WWH ::
Custom Search