Game Development Reference
In-Depth Information
so this shouldn't need to change. However, many platform games of this type include a feature
whereby the character can jump higher if you continue to hold down the jump key rather than
releasing it immediately. So we will make gravity a little weaker (1.5 pixels per step) when the
player initially presses the spacebar so that Zool can jump a little higher, but revert back to
normal gravity as soon as the player releases it again. So to get the maximum height out of a
jump, the player will need to hold the spacebar down for the duration of the jump.
The Zool Air State Object
1.
Reopen obj_zool_air and add a Create event. Include a Set Variable action ( control
tab) with Variable set to state and Value set to ZSTATE_JUMP .
Include a Set Gravity action ( move tab) with Direction set to 270 and Gravity set to 1.5 .
This sets an initial downwards force of 1.5 pixels per step on Zool when he is jumping.
2.
Include a Set Friction action with Friction set to 0 . We don't want any friction in the
air.
3.
4.
Add a Step, End Step event and include a Test Variable action ( control tab) with
Variable set to vspeed , Value set to 0 and Operation set to larger than .
5.
Immediately follow this with a Start Block action to group together the following
actions.
Include a Set Variable action with Variable set to state and Value set to ZSTATE_FALL .
6.
7. Include a Set Gravity action ( move tab) with Direction set to 270 and Gravity set to 2 .
This sets a downward force of 2 pixels per step to Zool when he is falling.
8. Immediately follow this with an End Block action to end the grouped events.
9. Add a Collision event with obj_solid . The first four actions in this event will be very
similar to the obj_solid collision event for obj_zool_land . You'll need to set Zool back
to his previous position, move him to the contact position in his current direction
(against all objects ), and then stop his movement. Try doing this for yourself and look
back at obj_zool_land (or Figure 3-8) to make sure you've got it right. Your last action
will need to be a Move Fixed action rather than a Speed Horizontal , to stop movement
in both directions.
10. After these four actions, include a Check Object action ( control tab) to check for the
Object , obj_platform at a Relative position of X= 0 , Y= 1 (underneath Zool).
11. Immediately follow this with a Change Instance action ( main1 tab) that changes into
obj_zool_land and performs ( Destroy and Create ) events as it does so. This will now
revert Zool back to the land state after a collision if he is supported by a platform.
12. Add a Key Release, Space event and include a Set Gravity action ( move tab) with
Direction set to 270 and Gravity set to 2 .
This last Key Release event may seem a bit odd without the corresponding Key Press event,
but the player will already have pressed the spacebar in another state object if they are jumping.
This Key Release event sets the gravity back to normal when the player releases the spacebar to
create the variable height jumping effect we're after. There are now a few changes we need to
make to obj_zool to accommodate the new object.
 
Search WWH ::




Custom Search