Game Development Reference
In-Depth Information
3.
Select the
End Step
event and change the line dealing with footsteps that says:
if( global.step_count mod 8 == 0 )
to:
if( image_index == 5 )
In
Zool
, we just wanted footsteps to be played at regular intervals (once every 8 steps).
His legs were too small and moved too fast to worry too much about exactly when they
were touching the ground. Flynn is much larger and it's clearer to see that his foot
touches the ground on about subimage 7 (see Figure 12-1). Therefore, we will play a
sound effect a couple of steps before this happens (subimage 5) as it generally takes a
little time for the sound effect to reach the critical part of the sound. Achieving the
desired result can take a little experimentation.
4.
Now, add the following two lines within the same block of code that depends on the
if( state == FSTATE_WALK )
condition:
if( x == xprevious )
state = FSTATE_STAND;
This will reset the walking state back to the standing state if Flynn doesn't actually
manage to move horizontally during a step. In other words, we won't keep playing the
walking animation if Flynn has been blocked by an obstruction.
Edit the code for the
Keyboard, Left
event and change the line that subtracts
2.5
from
hspeed
(using minus equals “
-=
”) to one that sets
hspeed
to
-10
(using just “
=
”). Now
include the following lines directly below that one to reset the walking animation back
to its starting frame when Flynn enters the walking state:
if( state != FSTATE_WALK )
image_index = 0;
5.
Do the same for the
Keyboard, Right
event, setting
hspeed
to
10
and including the
same two lines shown in step 5 immediately after it.
6.
7.
Add an
Other, Animation End
event and include an
Execute Code
action (
control
tab)
containing the following code:
{
state = FSTATE_STAND;
hspeed = 0;
}
This will put Flynn back into the standing state and stop his horizontal movement at
the end of each animation cycle.
Select the
Collision
event with
obj_solid
. There is a tweak we will make to the way that
collisions are handled with solid objects, as essentially there are two types of collisions:
those with Flynn's feet and those with the rest of his body. Previously, we have assumed
all collisions are with his whole body and should bring Flynn to a halt, but there are rare
situations (when ascending ramps) where he can collide with the corner of a platform
with his feet and come to a halt (see Figure 12-2). We can fix this problem by adjusting
the collision event to check if Flynn is standing on the object he has collided with and
handling the collision like we would do for a ramp instead. We still need the other
collision code (when he is not standing on the object), as Flynn should still come to a halt
if his head or upper body collides with a platform too. Change the code to read as
follows:
8.
Search WWH ::
Custom Search