Game Development Reference
In-Depth Information
An Alien's First Steps
So with a plan in place, we can now set about implementing some functionality for our game.
While it's all still fresh in our head, we'll begin by setting up constants for the eight different
movement states we're going to need, as well as creating empty objects for the four different state
objects.
Setting up State Constants and State Objects
1. Make sure you have an unaltered version of zool0.gmk opened and go to Define
Constants on the Resources menu.
2. Create the following state constants with their respective values: ZSTATE_STAND = 0 ,
ZSTATE_WALK = 1 , ZSTATE_JUMP = 2 , ZSTATE_FALL = 3 , ZSTATE_CLIMB = 4 , ZSTATE_CLING = 5 ,
ZSTATE_SLIP = 6 , ZSTATE_SKID = 7 . Note that we have prefixed all of these with the letter
Z (for Zool) in case we need to define states for other characters in the game later.
3. While it's open, create two more constants for facing left and right: FACE_LEFT = -1 ,
FACE_RIGHT = 1 . Note that we are using a negative value for left and a positive value for
right this time. These will be particularly useful as we can make regular use of the
relationship between these values and movement on the x-axis (as x-1 is one pixel to
the left, and x+1 is one pixel to the right). More of that later.
4. Create a new object called obj_zool , give it the spr_zool_stand_right sprite, and set its
depth to -1 (just in front of 0 ).
5. Create four more object resources called obj_zool_land , obj_zool_air , obj_zool_wall ,
and obj_zool_ice . Give each object the corresponding sprite: walk for land, jump for
air, climb for wall, and slip for ice. The facing direction of the sprite is not important,
but if you use the wrong sprite, then you may end up with a Zool that doesn't animate
properly. Set their depth to -1 and make obj_zool their parent.
6. Open up the test room and place a single instance of obj_zool on the bottom left of the
room so that he is standing in mid-air just above the floor.
Now let's create some simple walking functionality for Zool. We'll begin by setting up the
parent object, which can contain any functionality that is common to all Zool state objects. All
the child objects will inherit the events and actions of this object. One of the key functions we'll
make the parent object perform for all state objects will be to draw the appropriate sprite for
Zool's current state. The parent object will also be the first Zool object that gets created on each
level, so we'll use its Create event to set default values for variables as well.
The Zool Parent Object
1.
Add a Create event to obj_zool and include a Set Variable action ( control tab) that sets
a Variable facing to FACE_LEFT . We will use this variable to keep track of which way
Zool is facing just like before. Setting it to left in here makes Zool default to facing left
whenever he starts a level.
Now include a Change Instance action ( main1 tab) that changes into obj_zool_land
and sets Perform Events to yes . This last option makes sure that the Destroy event of
the current object ( obj_zool ) and the Create event of the object we're changing into
( obj_zool_land ) are both called as part of this action (in that order). We've only
mentioned the Create event in the past, as we don't use Destroy events very often.
2.
 
Search WWH ::




Custom Search