Prev: 8D77 Up: Map Next: 8E26
8DC4: Handle Serf
The handler for the serf (sprite IDs 21 to 30) when it is the character being played. The serf is moved by ControlPlayer, with a change in velocity of 20 a top speed of 20 and a slowing of 01 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 8DC4 LD BC,$2020 BC=2020 (the change in velocity and the top speed).
8DC7 LD DE,$0101 DE=0101 (the slowing of each velocity).
8DCA LD HL,$0707 HL=0707 (this is not used by ControlPlayer).
8DCD CALL ControlPlayer Call ControlPlayer to move the serf.
8DD0 LD E,(IX+$06) Fetch the X velocity.
8DD3 LD D,(IX+$07) Fetch the Y velocity.
8DD6 LD A,D Jump to HandlerSerf_Fire if the serf is not moving (both velocities are zero).
8DD7 OR E
8DD8 JR Z,HandlerSerf_Fire
8DDA LD A,($5C78) Fetch FRAMES.
8DDD AND %00000011 Keep only bits 0-1.
8DDF 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.
8DE1 LD A,(IX+$00) Fetch the sprite ID of the serf.
8DE4 AND %00000011 Keep only bits 0-1.
8DE6 ADD A,$21 Add 21 (the first of the sprites facing left).
8DE8 LD (IX+$00),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.
8DEB LD A,D Fetch the Y velocity.
8DEC AND A Jump to HandlerSerf_CompareAxes if the Y velocity is positive.
8DED JP P,HandlerSerf_CompareAxes
8DF0 NEG Make it positive.
HandlerSerf_CompareAxes 8DF2 LD C,A Keep the Y speed in C.
8DF3 LD A,E Fetch the X velocity.
8DF4 AND A Jump to HandlerSerf_Compare if the X velocity is positive.
8DF5 JP P,HandlerSerf_Compare
8DF8 NEG Make it positive.
HandlerSerf_Compare 8DFA CP C Jump to HandlerSerf_Horizontal if the serf is moving more across than up or down.
8DFB JR NC,HandlerSerf_Horizontal
The serf is moving up or down, so add 08 for the sprites facing up or 0C for those facing down.
8DFD LD A,D Fetch the Y velocity.
8DFE AND A Test the sign of the Y velocity.
8DFF LD A,(IX+$00) Fetch the sprite ID of the serf.
8E02 JP M,HandlerSerf_Vertical Jump to HandlerSerf_Vertical if the serf is moving up.
8E05 ADD A,$04 Add 04.
HandlerSerf_Vertical 8E07 ADD A,$08 Add 08.
HandlerSerf_SetSprite 8E09 LD (IX+$00),A Update the sprite ID of the serf.
8E0C 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 8E0F CALL ReadControls Call ReadControls to read the controls.
8E12 AND %00010000 Keep only bit 4 (fire).
8E14 CALL Z,ThrowSword Call ThrowSword to throw a sword if the fire button is pressed.
8E17 JP HandlerCharacter_Finish Jump to HandlerCharacter_Finish to finish handling the character.
The serf is moving across, so add 04 for the sprites facing right.
HandlerSerf_Horizontal 8E1A LD A,E Fetch the X velocity.
8E1B AND A Test the sign of the X velocity.
8E1C LD A,(IX+$00) Fetch the sprite ID of the serf.
8E1F JP M,HandlerSerf_SetSprite Jump to HandlerSerf_SetSprite if the serf is moving left.
8E22 ADD A,$04 Add 04.
8E24 JR HandlerSerf_SetSprite Jump to HandlerSerf_SetSprite to set the sprite of the serf.
Prev: 8D77 Up: Map Next: 8E26