Game Development Reference
In-Depth Information
Now we can use the names FACE_LEFT and FACE_RIGHT in our actions to refer to the constant
values of 1 and 2 . You may wonder if this is worth the effort, but we can assure you that your
programs will be more readable and you will create fewer bugs as a result. You will discover in
this topic that the ability to create neat, readable programs is essential to creating more
complicated games.
State Objects
Okay, so most of the “meat” of our game is going to be in the state objects for the Fishpod
character. Each state object will be simple in its own right, but as a whole, they will create a
complex interactive object. Try to keep one eye on the bigger picture (Figure 2-9) as we go step-
by-step through the implementation. We'll begin by tackling the simplest state object for the
standing state.
Creating the Standing State Object and Its Create Event
Create a new object called obj_pod_standing . You can set its Sprite to be either
spr_pod_stand_left or spr_pod_stand_right . This is just as a visual reminder for the
resource list because we will be selecting the correct sprite manually in the Create
event. Set its Depth value to -1 so that it appears in front of other objects, as the
player's character is generally the most important thing for the player to see in the
game.
1.
2.
Click on the Add Event button and select the Create event.
3.
Drag the Move Fixed action from the move tab into the actions list. Select the middle
Directions button to indicate no direction of movement and leave the Speed set to 0 .
This ensures that the character stops moving when it enters the standing state. Click
OK to close the action properties form (we won't remind you to do this from now on).
4.
Add the Set Gravity action ( move tab) to the actions list and leave Direction and
Gravity set to 0 . This ensures that gravity is turned off for the character when it enters
the standing state; otherwise, gravity would start it moving again.
5.
Include the Test Variable action ( control tab) in the actions list. We're going to use a
variable called facing to record whether the character is facing left or right, and use
our constants instead of a numerical value. Type facing into Variable , FACE_RIGHT into
Value , and leave Operation set to equal to . This checks to see whether the character is
facing right and only performs the next action if this is true.
6.
Include a Change Sprite action ( main1 tab) in the actions list. Select the
spr_pod_stand_right sprite and leave the other settings as they are.
Include another Test Variable action ( control tab) in the actions list. Type facing into
Variable , FACE_LEFT into Value , and leave Operation set to equal to . This checks to see
whether the character is facing left and only performs the next action if this is true.
7.
8.
Include a Change Sprite action ( main1 tab) in the actions list. Select the
spr_pod_stand_left sprite and leave the other settings as they are.
9.
You should now have a list of six actions for your Create event, as shown in Figure 2-
11. Notice how the names we have chosen for variables, sprites, and our constants all
help to make it easier to understand what the actions are doing. The lazier alternative
shown in Figure 2-12 is much harder to understand!
 
Search WWH ::




Custom Search