One of the most important elements in creating a great game is ensuring that the player has all the information they need to play the game. Much of this is usually presented in the heads-up display, otherwise known as the HUD. Every game has different components that can be a part of the HUD including things we need such as scoreboards and life counters.
Chapter 3/Fonts/RETRRG__.ttf
and click on Install. Then follow the directions when prompted.fnt_Scoreboard
.16
.fnt_WinLose
.32
. We now have all the in-game fonts we need, so click on OK.scr_Overlord_Draw
. We will start by setting the color and the font for the scoreboard text with this code:draw_set_color(c_white); draw_set_font(fnt_Scoreboard);
The first line of code sets the color with one of GameMaker: Studio's premade colors, c_white
. The next line then sets the scoreboard as the font.
draw_set_halign(fa_left); if ( lives >= 0 ) { draw_text(8, 0, "Lives: " + string(lives)); } else { draw_text(8, 0, "Lives: " ); }
To ensure the text is properly formatted, we set the horizontal alignment of the text to be aligned left. The text itself needs to be a string, which can be done in two ways. First, anything in quotation marks is considered a string, such as "Lives: "
. If we want to pass a number, such as the amount of lives we have, we need to convert it by passing through the string function. As seen here, if we have lives remaining we can concatenate the two things to create a single sentence Lives: 3 and draw it in the upper-left corner of the screen. If we are out of life, we draw the text without the concatenated value.
draw_set_halign(fa_right); draw_text(room_width-8, 0, "SCORE: " + string(score));
As we did with the previous text, we are setting the horizontal alignment, this time to the right. We then place the text in the proper position using the same concatenation method for the score.
obj_Overlord
and apply this script.scr_Overlord_Draw
:draw_set_font(fnt_WinLose); draw_set_halign(fa_center); if ( isVictory == true ) { draw_text(room_width / 2, room_height/2, "VICTORY"); } if ( isDefeat == true ) { draw_text(room_width / 2, room_height/2, "DEFEAT"); }
We change the font to fnt_WinLose
and set the horizontal alignment to be in the center. We don't want the text to be displayed all the time, instead we should only show either VICTORY or DEFEAT when it is appropriate. We have already implemented the code in the Overlord for the game condition, so we just check every step whether isVictory
is true
or isDefeat
is true
. As soon as the game is either won or lost, we draw the appropriate text in the center of the room.
The complete scr_Overlord_Draw
script should look like the following code:
draw_set_color(c_white); draw_set_font(fnt_Scoreboard); draw_set_halign(fa_left); draw_text(8, 0, "LIVES: " + string(lives)); draw_set_halign(fa_right); draw_text(room_width-8, 0, "SCORE: " + string(score)); draw_set_font(fnt_WinLose); draw_set_halign(fa_center); if ( isVictory == true ) { draw_text(room_width / 2, room_height/2, "VICTORY"); } if ( isDefeat == true ) { draw_text(room_width / 2, room_height/2, "DEFEAT"); }
3.144.48.204