Game Development Reference
In-Depth Information
11. Include a Set Variable action that sets the Variable digit_string to
string_char_at(text_string,digit) . This function gets a single character from the
first string ( text_string ) at a position determined by the second value ( digit ). So if
digit was 4 and text_string was "000500" , then it would get the fourth character in
the string, which is "5" . Note that this is still a string rather than a numerical value.
12. Include a Draw Sprite action ( draw tab) that draws spr_icon_digits at a Relative
position of X = 44+(16*digit) , Y = 20 and a Subimage of real(digit_string) . Notice that
the horizontal position of the sprite will move across by 16 pixels (the width of the
sprite) for each digit. The digit sprite contains the numbers 0-9 in sequential
subimages. So the real function simply turns the string that contains the digit back
into a numerical value so that it can be used to select the correct subimage of the
sprite.
13. Include a Set Variable action ( control tab) that sets digit Relative to -1 .
14. Include an End Block action. There should now be 12 actions in the Draw event of
obj_score , as shown in Figure 6-9.
Figure 6-9. The Draw event of obj_score
15. Reopen obj_controller and select the Create event.
16. Include a Create Instance action ( main1 tab) that creates an instance of obj_score .
There is no need to set position values, as the object will handle this itself.
If you run the game now, then you should see a score appearing in the top left corner of the
screen. The original game also kept track of the high score on the top right. We're not going to
take you through the steps of doing this, but if you want to then you can simply duplicate the
score object and change the position and icons. The highscore_value(1) function will provide
you with the top position on the standard Game Maker high-score table, but you'll need to
integrate the table itself into the game too if you want to see this value update. In our version,
you'll see that we've just made the high score display the score as well, for the time being. Next
up is the timer object, which keeps track of the amount of time left to complete the level.
 
Search WWH ::




Custom Search