Game Development Reference
In-Depth Information
12. Now, edit the Keyboard, Up event of obj_flynn_wall . There are a number of changes
to make here, so we'll just provide you with the result so that you can adjust it
accordingly:
1: {
2: if( state == FSTATE_CLIMB_TOP )
3: exit;
4:
5: if( is_climbable( facing, -3 ) == true )
6: {
7: vspeed = -3;
8: image_speed = 1;
9: state = FSTATE_CLIMB;
10: }
11: else
12: {
13: if( place_meeting( x+(facing*60), y-130, obj_solid ) == false )
14: {
15: state = FSTATE_CLIMB_TOP;
16: image_index = 0;
17: image_speed = 1;
18: }
19: }
20: }
Notice that this event exits without doing anything if Flynn is already in the climbing-
on-top state. He clearly can't climb any higher if he is already in this state.
Line 5 checks to see if it is possible to move 3 pixels up from Flynn's current
position and then lines 7-9 start him moving up at a speed of 3 pixels per step if he can.
This speed looks about right for the climbing animation, and we need to make sure the
animation is playing forward by setting image_speed to 1 (we'll need to play it backward
when he moves down the wall).
If it's not possible to move any further up the wall, then line 13 checks to see if
Flynn would collide with anything solid if he was moved 60 pixels in the direction he is
facing and 130 pixels up. Why these values? Well, that's the relative distance between
Flynn in the first frame of the climbing up animation and the last frame (the blue
arrow in Figure 12-3, right). We only want him to start climbing up if the end position
is free of obstructions. If it is free, then lines 15-17 put Flynn into the climbing on top
state and set his animation playing at a normal forward speed starting from the first
frame.
 
Search WWH ::




Custom Search