Prev: 36215 Up: Map Next: 36390
36292: Handle Serf
The handler for the serf (sprite IDs 33 to 48) when it is the character being played. The serf is moved by ControlPlayer, with a change in velocity of 32 a top speed of 32 and a slowing of 1 on each frame. When it is moving, every fourth frame the next frame of the animation is chosen for the direction of travel (the four sets are left, right, up and down) and the sound of walking is made. Then the fire button throws a sword (see ThrowSword), and HandlerCharacter_Finish does the rest.
Input
IX The serf entity
HandlerSerf 36292 LD BC,8224 BC=8224 (the change in velocity and the top speed).
36295 LD DE,257 DE=0257 (the slowing of each velocity).
36298 LD HL,1799 HL=1799 (this is not used by ControlPlayer).
36301 CALL ControlPlayer Call ControlPlayer to move the serf.
36304 LD E,(IX+6) Fetch the X velocity.
36307 LD D,(IX+7) Fetch the Y velocity.
36310 LD A,D Jump to HandlerSerf_Fire if the serf is not moving (both velocities are zero).
36311 OR E
36312 JR Z,HandlerSerf_Fire
36314 LD A,(23672) Fetch FRAMES.
36317 AND %00000011 Keep only bits 0-1.
36319 JR NZ,HandlerSerf_Fire Jump to HandlerSerf_Fire unless this is every fourth frame.
Move on to the next frame of the animation, for the left set of sprites.
36321 LD A,(IX+0) Fetch the sprite ID of the serf.
36324 AND %00000011 Keep only bits 0-1.
36326 ADD A,33 Add 33 (the first of the sprites facing left).
36328 LD (IX+0),A Update the sprite ID of the serf.
Work out which axis the serf is moving fastest on, by comparing the sizes of the velocities.
36331 LD A,D Fetch the Y velocity.
36332 AND A Jump to HandlerSerf_CompareAxes if the Y velocity is positive.
36333 JP P,HandlerSerf_CompareAxes
36336 NEG Make it positive.
HandlerSerf_CompareAxes 36338 LD C,A Keep the Y speed in C.
36339 LD A,E Fetch the X velocity.
36340 AND A Jump to HandlerSerf_Compare if the X velocity is positive.
36341 JP P,HandlerSerf_Compare
36344 NEG Make it positive.
HandlerSerf_Compare 36346 CP C Jump to HandlerSerf_Horizontal if the serf is moving more across than up or down.
36347 JR NC,HandlerSerf_Horizontal
The serf is moving up or down, so add 8 for the sprites facing up or 12 for those facing down.
36349 LD A,D Fetch the Y velocity.
36350 AND A Test the sign of the Y velocity.
36351 LD A,(IX+0) Fetch the sprite ID of the serf.
36354 JP M,HandlerSerf_Vertical Jump to HandlerSerf_Vertical if the serf is moving up.
36357 ADD A,4 Add 4.
HandlerSerf_Vertical 36359 ADD A,8 Add 8.
HandlerSerf_SetSprite 36361 LD (IX+0),A Update the sprite ID of the serf.
36364 CALL SoundsWalking Call SoundsWalking to make the sound of walking.
See whether the fire button is pressed, and then do what every character does.
HandlerSerf_Fire 36367 CALL ReadControls Call ReadControls to read the controls.
36370 AND %00010000 Keep only bit 4 (fire).
36372 CALL Z,ThrowSword Call ThrowSword to throw a sword if the fire button is pressed.
36375 JP HandlerCharacter_Finish Jump to HandlerCharacter_Finish to finish handling the character.
The serf is moving across, so add 4 for the sprites facing right.
HandlerSerf_Horizontal 36378 LD A,E Fetch the X velocity.
36379 AND A Test the sign of the X velocity.
36380 LD A,(IX+0) Fetch the sprite ID of the serf.
36383 JP M,HandlerSerf_SetSprite Jump to HandlerSerf_SetSprite if the serf is moving left.
36386 ADD A,4 Add 4.
36388 JR HandlerSerf_SetSprite Jump to HandlerSerf_SetSprite to set the sprite of the serf.
Prev: 36215 Up: Map Next: 36390