Prototyping - Introduction Design
The introduction room is the first thing players see when they start the game. We'll have to come up with an object design that accurately reproduces the original sequence.
Introduction Flow
The introduction is a fixed sequence of screens and events. The above diagram shows the five screens and details the flow through one of the screens. The general idea is that each screen fades in, then the subtitle text fades in. User input triggers fade outs. There could be any combination of background screen graphic and/or text including no background screen. The exception is the action credits screen, which requires a fully working engine. For now, we'll create a replacement screen that conveys the same information.
We can recreate this introduction using two concepts: A finite state machine to control the functional flow and a custom script to drive the machine with the proper graphics and text.
Finite State Machine
Each of the actions in the introduction is tied to a single state in our machine. We'll maintain two sets of variables for text and screens, both the current and the next (sort of like a back buffer). The machine starts in the read state and we read the upcoming screens in to the next. When we're ready to display the next screen, we just swap the variable and travel through the machine until we're back to the read state. Here's the breakdown:
State | Purpose |
---|---|
Read | The starting state. We read from our script to load the next screen/text. In some cases, we may sleep for child objects like the action credits sequence. |
Swap | Move the next variables to the current variables. All text and screens should already be faded out in this state so the process is invisible |
Screen In | Fade the screen from 0 alpha to 100% |
Text In | Fade the text from 0 alpha to 100% |
Listen | Wait for user input |
Text Out | Fade the text out |
Screen Out | Fade the screen out |
Sleep | Hibernate the object and spawn a child object to do extra work. When the child is destroyed, we move back to read. |
This finite state machine will be implemented in a single object called obj_introscene
Introduction Script Language
We could easily hardcode the sequence of events in to the introduction object, but we'll take a different approach by building a custom script that we'll put in to an external text file and interpret at runtime. This will be a very simple approach by choosing a delimiter, say '['. For now, we'll only specify the elements of the scripting language and create the target file in the next part. Note that this approach is really meant to demonstrate an alternatate approach. Really, a developer should think about using a known standard to markup data, such as XML or maybe JSON.
Let's identify the dynamic elements of the introduction an assign a delimited control that we can alter:
Element | Control | Purpose |
---|---|---|
Set Text | None | No delimiter means we interpret the line as text |
Set Screen | [s | Set the background screen based on the SCR file sprite name |
Set Text Color | [c | Set the color of text. |
Set Text Vertical Alignment | [v | Set the vertical alignment of text |
Set Text Horizontal Alignment | [h | Set the horizontal alignment of text |
Create New Object | [o | Spawn a child object (we'll use this with the action intro) |
End Scene | [e | End the scene |