Prototyping - Enhancements
Our prototype now resembles the original Traffic Department 2192. This time we'll add some basic enhancements: Make a scalable view during gameplay, and add the ability to skip missions entirely and just watch the storylines. One subtle enhancement we've already achieved is boosting the FPS to 60 by virtue of using GameMaker.
Just to reiterate, When implementing a game design, I prefer to get it working in some basic, small-scale form. Then starting adding features to this prototype. After understand what the full feature set includes, then we go back and design the engine from the ground up.
Objects
We'll be adding a new object that supports skipping missions. It sits between the briefing and the mission start.
Concept | Object | Notes |
---|---|---|
Mission Skipping | obj_missionskip | Gives the player the option to skip the mission gameplay and just go from briefing to debriefing. |
GML Code
The new object supports mission skipping. We'll edit the camera and keyboard objects to support the view rescaling.
obj_keyboard: Begin Step 1
We'll add these three lines within this event to dispatch new keys for zooming and skipping that are handled in the appropriate objects.
1 2 3 |
if keyboard_check_pressed(ord('W')) then ds_stack_push(input_stack, "push_w") if keyboard_check_pressed(ord('X')) then ds_stack_push(input_stack, "push_x") if keyboard_check_pressed(ord('Z')) then ds_stack_push(input_stack, "push_z") |
obj_camera: Create 2
New variables to support zooming and rescaling
1 2 3 4 5 |
/* Zooming */ rescale = true zoom_in = false zoom_out = false current_width = view_wview[0] |
obj_camera: Step 1
Handle new keys Z and X. This code snippet includes our old code so just replace the old.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
///Process commands while !ds_stack_empty(command_stack) { var cmd = ds_stack_pop(command_stack) switch cmd { case "hold_left": x-=10; break; case "hold_right": x+=10; break; case "hold_up": y-=10; break; case "hold_down": y+=10; break; case "push_x": { if zoom_out == zoom_in zoom_out = true } break; case "push_z": { if zoom_out == zoom_in zoom_in = true } break; } } |
obj_camera: Step 2
Actual zooming is done by manipulating the GameMaker views. We do a smooth slide from 1x, 2x, 3x, etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
///Zooming if zoom_out { view_wview[0]+=32; view_hview[0]+=20; rescale = true if view_wview[0] mod current_width == 0 zoom_out = false } if zoom_in { if view_wview[0] > 320 { view_wview[0]-=32; view_hview[0]-=20; rescale = true } if view_wview[0] mod current_width == 0 zoom_in = false } |
obj_camera: End Step 3
Here we ensure that the player's ship stays centered as much as possible. Extreme rescaling may break this.
1 2 3 4 5 6 7 |
///Rescale view if rescale { view_hborder[0] = view_wview[0] / 2; view_vborder[0] = view_hview[0] / 2; rescale = false } |
obj_briefing: Destroy 3
The final version of our briefing destructor. This time we'll pass control to the mission skip option object
1 2 3 4 5 6 7 8 9 |
///Next room if room == rm_brief then { var obj = instance_create(0,0,obj_missionskip); obj.mission_title = string_upper(mission_title[gamedata.current_mission]) } if room == rm_debrief then room_goto(rm_mainmenu) |
obj_missionskip: Create 1
Registration and references
1 2 3 4 |
///Register keyboard and set references keyboard_register(id) gamedata = instance_find(obj_currentgame,0) |
obj_missionskip: Create 2
Some variables, which include the target room that we'll manipulate.
1 2 3 4 5 6 7 8 9 10 |
///Init vars text_alpha = 0 fade_in = true fade_out = false next_room = rm_mission mission_title = "" subtitle = "PRESS -W- TO AUTOWIN. PRESS ANY KEY TO PLAY" |
obj_missionskip: Destroy 1
Deregister and move along
1 2 3 4 |
///Deregister keyboard_deregister(id) room_goto(next_room) |
obj_missionskip: Step 1
Process input including our new key to skip missions. Any other key to start.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
///Process input while !ds_stack_empty(command_stack) { var cmd = ds_stack_pop(command_stack) if fade_in == false && fade_out == false { switch cmd { case "push_w": { next_room = rm_debrief fade_out = true }; break; case "any": fade_out = true; break; case "escape": instance_destroy(); break; } } } |
obj_missionskip: Step 2
Fading in and out and destroying.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
///Fading if fade_in { if text_alpha < 1 then text_alpha += 0.05 else fade_in = false } if fade_out { if text_alpha > 0 then text_alpha -= 0.05 else instance_destroy() } |
obj_missionskip: Draw 1
Draw the mission title banner
1 2 3 4 5 6 7 8 9 10 |
///Draw mission title draw_set_font(global.mission_font) text_x = max(view_wview[0]/2 - (string_width(mission_title)/2),view_wview[0]*0.05) text_y = round(view_hview[0]*0.45) draw_set_alpha(text_alpha) draw_set_halign(fa_left) draw_set_color(c_red) draw_text(text_x,text_y,mission_title) |
obj_missionskip: Draw 2
Draw the subtitle instructions
1 2 3 4 5 6 7 8 9 10 |
///Draw subtitle draw_set_font(global.little_font) text_x = max(view_wview[0]/2 - (string_width(subtitle)/2),view_wview[0]*0.05) text_y = round(view_hview[0]*0.8) draw_set_alpha(text_alpha) draw_set_halign(fa_left) draw_set_color(c_green) draw_text(text_x,text_y,subtitle) |