We have a good end to the levels, but the player may not be sure what to do. What we need is a bit of a story to sell the idea of destroying towers and explaining what it is the player needs to do in each level. To do this we will add a screen, much like the Score Screen at the start of each level:
scr_Menu_Button_Start
, with some very familiar code:draw_sprite(spr_Button_Start, 0, startX, startY); if (win_Y > startY - start_ZoneHeight && win_Y < startY + start_ZoneHeight) { if (win_X > startX - start_ZoneWidth && win_X < startX + start_ZoneWidth) { draw_sprite(spr_Button_Start, 1, startX, startY); if (mouse_check_button_pressed(mb_left)) { isGameActive = true; instance_destroy(); } } }
All the standard button code is here, but when the button is clicked, we activate the gameplay and then destroy the Story screen object. The start_ZoneWidth
and start_ZoneHeight
variables used here haven't been initialized yet, but we will be doing that shortly.
scr_Global_Dialogue
, and write the dialog that we need:globalvar dialogue; dialogue = ds_map_create(); ds_map_add(dialogue, Level_01, "Welcome to Destruct! A tower toppling game. # Let's start with some basic training. Here we have a glass tower that needs to come down. You have one stick of TNT to use to completely clear the Zone. # Let's see what you can do."); ds_map_add(dialogue, Level_02, "Temporary Dialogue for Level 02"); ds_map_add(dialogue, Level_03, "Temporary Dialogue for Level 03"); ds_map_add(dialogue, Level_04, "Temporary Dialogue for Level 04"); ds_map_add(dialogue, Level_05, "Temporary Dialogue for Level 05"); ds_map_add(dialogue, Level_06, "Temporary Dialogue for Level 06"); ds_map_add(dialogue, Level_07, "Temporary Dialogue for Level 07"); ds_map_add(dialogue, Level_08, "Temporary Dialogue for Level 08"); ds_map_add(dialogue, Level_09, "Temporary Dialogue for Level 09"); ds_map_add(dialogue, Level_10, "Temporary Dialogue for Level 10"); ds_map_add(dialogue, Level_11, "Temporary Dialogue for Level 11"); ds_map_add(dialogue, Level_12, "Temporary Dialogue for Level 12");
We make a new global variable and attach it to the Map data structure we create. For each entry we need to have a Key and a Value for that key. Here we use the name of each room as a key and write the dialog as the value. We need text for every room in the game so it doesn't error out, so we have temporary dialog for rooms 2-12 that you can replace with your own text. In the dialog for Level 01 we are using #
which is a special character used to start a new paragraph. This will make large amounts of text a bit more readable.
scr_Global_GameStart
and call this script.obj_StoryScreen
, with a Depth of -100
.scr_StoryScreen_Create
, to initialize the variables:isGameActive = false; screenX = 320; screenY = 200; startY = 440; startX = 320; start_ZoneWidth = 128; start_ZoneHeight = 32; myText = ds_map_find_value(dialogue, room); textLength = 0;
We stop gameplay and then set six variables for the location of the text we will be drawing. We then load up the text from the Map based on the room the player is currently in. The last variable we have, textLength
, is going to be used for an inventory effect, where the text appears to be typed in over time.
scr_StoryScreen_DrawGUI
, that draws everything:draw_sprite(spr_Screen_BG, 0, screenX, screenY); draw_set_color(c_black); draw_set_halign(fa_center); draw_set_font(fnt_Large); draw_text(screenX, 60, string(room_get_name(room))); draw_set_halign(fa_left); draw_set_font(fnt_Small); textLength++; writeText = string_copy(myText, 1, textLength); draw_text_ext(160, 120, writeText, -1, 320); draw_set_font(-1); win_X = window_mouse_get_x(); win_Y = window_mouse_get_y(); scr_Menu_Button_Start();
As we did with the Score Screen, we draw the background and set the color, alignment, and font for the title of the level. Next is the typewrite effect for the dialog to be shown on screen. We change the alignment and font for the dialog and start increasing the textLength
variable by one step each. This value is what determines how many characters from the dialog need to be copied over to the writeText
variable, which means that the text will grow over time. We are using the draw_text_ext
function, which allows us to limit how wide the paragraph can be before it drops down a line, in this case 320 pixels. Once again at the end we get the mouse location for the start button to work.
scr_Overlord_Create
:instance_create(0, 0, obj_StoryScreen);
3.148.107.254