Let’s Make: Traffic Department 2192 – Part 27

Prototyping - Programming the HUD

We'll divert from the world and enemies this time in order to bring more information to the player. We'll program up our HUD design from part 23 including all the widgets. We'll rely on the GameMaker GUI abstraction, which is just a quick way to manipulate view space directly (as opposed to world space).

Then we need to update a few of our older objects to make sure they're sending or updated the HUD as necessary

However, I forgot to include the HUD files in our asset extraction part, so I'll run through the process here. We'll focus on three files: HUD.WIN, TD.FAC, and TD.WEA. We'll rename the files in sequence to HUD.HUD, FAC.FAC, and WEA.WEA.

C Code

We run the files through the following code block to get our bitmap assets.

HUDTOBMP.c

 

Objects

We'll use two new objects in this part. First is an AI specific object that ties to ships. Second is a controller-like object that will have several duties by the end of the prototype

Concept Object Notes
Heads-Up Display obj_hud Each ship gets an associated AI object (even the player ship). This object will pass control commands to the ship like the player does with the keyboard. We'll only make the passive path-following AI for now.

 

GML Code

Most of our GameMaker work will be in the new object.

obj_hud: Create 1

Variables for our HUD object and each of its widgets. This also includes creating the two minimap surfaces.

 

obj_hud: Destroy 1

Free the two minimap surfaces

 

obj_hud: Room Start 1

Set the many references we need to tie all the game information together

 

obj_hud: Step 1

We start each step by resetting and collecting all the HUD data.

 

obj_hud: Step 2

Next we move the message ticker if there's a current message

 

obj_hud: Step 3

Finally, we fade out. I chose to actually end the scene based on the HUD fading, but this should probably move to obj_hq during a refactor pass.

 

obj_hud: Draw GUI 1

Render the HUD and all it's elements

 

obj_hud: Draw GUI 2

Render the message ticker.

 

obj_hud: Draw GUI 3

Draw the overall fading effect

 

obj_hud: Draw Begin 1

This is the trigger for creating the minimap. It only runs once during the first frame of the mission

 

obj_hud: Draw Begin 2

Reset the ship overlay. All objects will draw to it. We do this in Draw begin because ships and weapon shots draw their position to the minimap during Draw.

 

Script: Hud Message

A function callable from any object in the mission to send a message to the HUD.

 

obj_camera: End Step 2

Update the minimap position relative to the camera.

 

obj_ship: Draw 3

Draw ships to the minimap

 

obj_fire: Draw 2

Draw weapons fire to the minimap