Let’s Make: Traffic Department 2192 – Part 18

Prototyping - Introduction Programming

We're going to implement the design from the last part by constructing the primary object obj_introscene. A key feature of this object is that it interprets the intro script language we created last time. First we need to build the script into a data file that we'll include with GameMaker.

Introduction Script

The following data is the contents of introscene.txt, which uses our custom scripting language to storyboard the introduction.

 

 

Objects

We'll introduce a few more objects in to the prototype.

The Introduction Controller - obj_introscene

This object implements the finite state machine by declaring, defining, and handling the states. This means we'll also be interpreting the script above in the read state, and displaying the scene to the screen in most other states.

The Credits Placeholder - obj_credits

We can't recreate the credits sequence yet because we haven't created the gameplay engine. We'll add a placeholder object that displays the same information for now. While this object is active, the controller object is sleeping.

 

GML Code

We'll add code to both of our objects under several events. We'll also add a script.

obj_introscene: Create 1

The first thing we'll do is register the intro object with the keyboard handler so that it receives commands. Almost all active objects will do this in their constructor. If GameMaker supported multiple inheretence, we'd want all objects to inherent a keyboard listener prototype rather than explicitly calling the procedure.

 

obj_introscene: Create 2

Here we define all the states in our finite state machine as an enum type

 

obj_introscene: Create 3

Here we define the applicable variables for the introscene object. Remember that we're building type of front and back buffer, so we'll have to declare a duplicate set of variables for both current screen and next screen that we'll swap later.

 

obj_introscene: Create 4

We have to read in the introscene.txt file so that we can follow the sequence of events without repeatedly accessing the file.

 

obj_introscene: Destroy 1

The destructor will do two things: remove the keyboard reference and push us to the next room.

 

obj_introscene: Step 1

We'll have to process commands from the keyboard handler at the beginning of every step.

 

obj_introscene: Step 2

This is where the magic happens -- We check which state we're in, do the work of the state, which includes interpreting our script, and then push us to the next state as necessary

 

obj_introscene: Draw 1

We have to render the results of all our work to the screen in this event.

 

obj_keyboard: Begin Step 1

Now that we have an object listening to the 'escape' key, we have to add it to th keyboard handler. Add this line:

 

Script: keyboard_register

This script registers any object that uses it with the keyboard handler so that it receives input commands.

 

Script: keyboard_deregister

This removes the object as a keyboard listener

 

obj_credits: Create 1

We'll register the keyvoard and set references

 

obj_credits: Create 2

Set the fading variables specific to the credits display

 

obj_credits: Create 3

Kickoff the credits by changing the music

 

obj_credits: Destroy 1

When the credits object is finished, we have to remove the keyboard, restore the sounds, and tell the intro object to get back to work.

 

obj_credits: Step 1

The credits object must process keyboard commands

 

obj_credits: Step 2

There are a few fading routines which triggers entry and exit of the object

 

obj_credits: Draw 1

Finally, the credits object renders static information to the screen, which is harded here