Game Development Reference
In-Depth Information
The scoreboard might contain
Properties
Score
Ships left
Level
Functions
updateScore()
updateShips()
updateLevel()
You can see that type of planning can illuminate most of the parts that will be necessary to make
a working game. Beyond that, you can take this design and use it to create actual working parts
for your game. While this process may seem a bit complicated now, as we start to create games,
you will see how this type of planning and design can help immensely when you build games in
AS3. You will also notice that games can be very tricky to develop. When a game needs to be
high performance or needs to fit into a particular file size, many of these rules and ideas can go
out the window. We will try to keep as close as possible to these principles, but where we
diverge, there will be good reasons for it that we'll explain.
Creating the basic game framework
Now, we are going to create a very basic version of our game framework to illustrate how games
will be created in the rest of this topic. This framework will be updated, altered, improved, and
changed as the games get more intricate, but we need to start someplace, and this is it. We will
create the code for a very simple game. The game itself is not really consequential, but the
structure of the code is very important. However, don't worry if you don't get this right away, as
we will be covering these topics over and over as we progress. Here are the basic elements of
the simple game.
This game is no more than a simple program to test to see if the mouse button has been clicked.
However, this very simple game will be used to illustrate the major parts of the game framework.
The first of these is the
state loop
. Our game can be in one of three states: an initialization state,
a play state, and a game over state. The game decides what it needs to do by testing to see
which state it is currently running within. This constant testing is the state loop. For example, in
the play state, the game waits for the user to click the mouse button, and when the button is
clicked, the state is changed to game over. The state loop is constantly checking which state the
game's in, so when it sees this change it takes the appropriate action and runs the game over
code. This iterative checking of the state loop is controlled by a
game timer
, the second of the
core parts of our framework. Finally, when the mouse button is clicked, a function is called that
will process the click. This is the
event model
, and forms the last core part of our framework.
Let's look over those three parts in more detail.
State loop
The state loop is the traffic cop that will direct the game program into a set of actions. A very
basic version of this can be created using some constants and a
switch
statement. Constants are