Prev: 8DC4 Up: Map Next: 8EA0
8E26: Handle Knight
The handler for the knight (sprite IDs 01 to 10) when it is the character being played. It is the same as HandlerSerf, except that the slowing is 03 on each frame and the fire button throws an axe (see ThrowAxe). The second part of this routine is used by the other characters as well: it makes creatures (see SpawnCreature), takes energy from the player every sixteen frames, and displays the character.
Input
IX The knight entity
HandlerKnight 8E26 LD BC,$2020 BC=2020 (the change in velocity and the top speed).
8E29 LD DE,$0303 DE=0303 (the slowing of each velocity).
8E2C LD HL,$0707 HL=0707 (this is not used by ControlPlayer).
8E2F CALL ControlPlayer Call ControlPlayer to move the knight.
8E32 LD E,(IX+$06) Fetch the X velocity.
8E35 LD D,(IX+$07) Fetch the Y velocity.
8E38 LD A,D Jump to HandlerKnight_Fire if the knight is not moving (both velocities are zero).
8E39 OR E
8E3A JR Z,HandlerKnight_Fire
8E3C LD A,($5C78) Fetch FRAMES.
8E3F AND %00000011 Keep only bits 0-1.
8E41 JR NZ,HandlerKnight_Fire Jump to HandlerKnight_Fire unless this is every fourth frame.
Move on to the next frame of the animation, for the left set of sprites.
8E43 LD A,(IX+$00) Fetch the sprite ID of the knight.
8E46 AND %00000011 Keep only bits 0-1.
8E48 INC A Add 01 (the first of the sprites facing left).
8E49 LD (IX+$00),A Update the sprite ID of the knight.
Work out which axis the knight is moving fastest on, by comparing the sizes of the velocities.
8E4C LD A,D Fetch the Y velocity.
8E4D AND A Jump to HandlerKnight_CompareAxes if the Y velocity is positive.
8E4E JP P,HandlerKnight_CompareAxes
8E51 NEG Make it positive.
HandlerKnight_CompareAxes 8E53 LD C,A Keep the Y speed in C.
8E54 LD A,E Fetch the X velocity.
8E55 AND A Jump to HandlerKnight_Compare if the X velocity is positive.
8E56 JP P,HandlerKnight_Compare
8E59 NEG Make it positive.
HandlerKnight_Compare 8E5B CP C Jump to HandlerKnight_Horizontal if the knight is moving more across than up or down.
8E5C JR NC,HandlerKnight_Horizontal
The knight is moving up or down, so add 08 for the sprites facing up or 0C for those facing down.
8E5E LD A,D Fetch the Y velocity.
8E5F AND A Test the sign of the Y velocity.
8E60 LD A,(IX+$00) Fetch the sprite ID of the knight.
8E63 JP M,HandlerKnight_Vertical Jump to HandlerKnight_Vertical if the knight is moving up.
8E66 ADD A,$04 Add 04.
HandlerKnight_Vertical 8E68 ADD A,$08 Add 08.
HandlerKnight_SetSprite 8E6A LD (IX+$00),A Update the sprite ID of the knight.
8E6D CALL SoundsWalking Call SoundsWalking to make the sound of walking.
See whether the fire button is pressed.
HandlerKnight_Fire 8E70 CALL ReadControls Call ReadControls to read the controls.
8E73 AND %00010000 Keep only bit 4 (fire).
8E75 CALL Z,ThrowAxe Call ThrowAxe to throw an axe if the fire button is pressed.
This entry point is used by the routines at HandlerWizard and HandlerSerf.
Make creatures, use up some energy and display the character. This is also where the serf and the wizard come in.
HandlerCharacter_Finish 8E78 CALL SpawnCreature Call SpawnCreature to make a creature, if one is due.
8E7B LD A,($5E12) Fetch the counter from CounterLow.
8E7E AND %00001111 Keep only bits 0-3.
8E80 JR NZ,HandlerCharacter_Display Jump to HandlerCharacter_Display unless this is every sixteenth frame.
8E82 LD A,($5E28) Fetch the energy of the player from PlayerEnergy.
8E85 DEC A Decrease the energy by one.
8E86 JR Z,LoseLife Jump to LoseLife if there is no energy left.
8E88 LD ($5E28),A Update the energy of the player in PlayerEnergy.
8E8B CALL DrawChicken Call DrawChicken to redraw the chicken.
This entry point is used by the routines at HandlerWeapon, HandlerBatlet, MoveCreature, HandlerSparkle and HandlerPop.
HandlerCharacter_Display 8E8E CALL DisplayEntity Call DisplayEntity to display the character.
8E91 JP SetEntityAttributes_Moved Jump to SetEntityAttributes_Moved to set the attributes of the cells it covers.
The knight is moving across, so add 04 for the sprites facing right.
HandlerKnight_Horizontal 8E94 LD A,E Fetch the X velocity.
8E95 AND A Test the sign of the X velocity.
8E96 LD A,(IX+$00) Fetch the sprite ID of the knight.
8E99 JP M,HandlerKnight_SetSprite Jump to HandlerKnight_SetSprite if the knight is moving left.
8E9C ADD A,$04 Add 04.
8E9E JR HandlerKnight_SetSprite Jump to HandlerKnight_SetSprite to set the sprite of the knight.
Prev: 8DC4 Up: Map Next: 8EA0