Game Development Reference
In-Depth Information
1: {
2: switch( state )
3: {
4: case ESTATE_MOVE:
5:
6: if( check_standing_on( obj_platform, 1, 0 ) != true )
7: move_on_top_of( -1, obj_platform );
8:
9: hspeed = facing*8;
10:
11: if( is_passable_for_enemy( facing*32 ) != true ||
12: irandom_range( 0, 300 ) == 0 )
13: {
14: state = ESTATE_WAIT;
15: alarm[0] = irandom_range( 10, 100 );
16: hspeed = 0;
17: }
18:
19: if( image_index == 6 || image_index == 18 )
20: sound_play( snd_bootstep );
21:
22: break;
23:
24: case ESTATE_ATTACK:
25: break;
26:
27: case ESTATE_WAIT:
28: hspeed = 0;
29: break;
30: }
31: }
You can see that we are using a switch statement to create a simple state machine
again. Lines 6-7 are a brute-force method of bringing the skeleton's feet in contact with
a platform and line 9 sets him moving in the direction he is currently facing.
Line 11 checks to see if there are any obstructions 32 pixels ahead that should
trigger the next block of code, and line 12 makes it happen just randomly sometimes
anyway to make the skeleton slightly less predictable.
Lines 14-16 put the skeleton into the waiting state and randomly set the timer to
wake him up again. Then lines 19 and 20 play footstep sound effects on the
appropriate frames of the walking animation (as we did for Flynn).
The attacking state case on lines 24-25 is empty for the moment, but we'll come
back to it later. Line 28 makes sure that the skeleton stays put in the wait state.
Search WWH ::




Custom Search