Prev: 80CB Up: Map Next: 8134
80D2: Handle Wizard
The handler for the wizard, which has the sprite IDs 11 to 20. The speed limits and the friction are passed to ControlPlayer, which reads the controls and moves the player. Then, every fourth frame while the player is moving, the walking frame is advanced and the sprite is turned to face the direction of the strongest movement. If the fire button is pressed then a fireball is thrown by ThrowFireball. The routine finishes by jumping to the code that is shared with the other characters at HandlerCharacter_Finish.
Input
IX The player entity
Control the player. BC holds the speed limits (C for X and B for Y, where B is also the acceleration) and DE holds the friction (E for X and D for Y). HL is not used by ControlPlayer.
HandlerWizard 80D2 LD BC,$2020 Set the speed limits in BC to 20 on both axes.
80D5 LD DE,$2020 Set the friction in DE to 20 on both axes.
80D8 LD HL,$2020 HL=2020, which is not used by ControlPlayer.
80DB CALL ControlPlayer Call ControlPlayer to control the player.
Only change the walking frame if the player is moving.
80DE LD E,(IX+$06) Fetch the X velocity of the player into E.
80E1 LD D,(IX+$07) Fetch the Y velocity of the player into D.
80E4 LD A,D Jump to HandlerWizard_Fire if the player is not moving.
80E5 OR E
80E6 JR Z,HandlerWizard_Fire
The walking frame only changes every fourth frame.
80E8 LD A,($5C78) Fetch FRAMES.
80EB AND %00000011 Keep only bits 0-1.
80ED JR NZ,HandlerWizard_Fire Jump to HandlerWizard_Fire if the result is not zero.
Move on to the next of the four walking frames.
80EF LD A,(IX+$00) Fetch the sprite ID of the player.
80F2 AND %00000011 Keep only bits 0-1.
80F4 ADD A,$11 Add 11 which gives the next walking frame.
80F6 LD (IX+$00),A Write the new sprite ID back to the player.
Make a copy of the Y speed, ignoring the direction.
80F9 LD A,D Fetch the Y velocity from D, then jump to HandlerWizard_AbsoluteX if it is positive.
80FA AND A
80FB JP P,HandlerWizard_AbsoluteX
80FE NEG Make the Y speed positive.
HandlerWizard_AbsoluteX 8100 LD C,A Keep the Y speed in C.
Make a copy of the X speed, ignoring the direction.
8101 LD A,E Fetch the X velocity from E, then jump to HandlerWizard_CompareAxes if it is positive.
8102 AND A
8103 JP P,HandlerWizard_CompareAxes
8106 NEG Make the X speed positive.
HandlerWizard_CompareAxes 8108 CP C Jump to HandlerWizard_Horizontal if the X speed is the strongest movement.
8109 JR NC,HandlerWizard_Horizontal
The Y movement is the strongest, so face up or down.
810B LD A,D Test the sign of the Y velocity.
810C AND A
810D LD A,(IX+$00) Fetch the sprite ID of the player.
8110 JP M,HandlerWizard_Vertical Jump to HandlerWizard_Vertical if the player is moving up.
8113 ADD A,$04 Add 04 to select the sprites for moving down.
HandlerWizard_Vertical 8115 ADD A,$08 Add 08.
HandlerWizard_SetSprite 8117 LD (IX+$00),A Write the new sprite ID back to the player.
811A CALL SoundsWalking Call SoundsWalking to make the walking sound.
Check if the fire button is being pressed.
HandlerWizard_Fire 811D CALL ReadControls Call ReadControls to read the controls.
8120 AND %00010000 Keep only bit 4.
8122 CALL Z,ThrowFireball Call ThrowFireball if the fire button is pressed.
8125 JP HandlerCharacter_Finish Jump to HandlerCharacter_Finish to finish handling the character.
The X movement is the strongest, so face left or right.
HandlerWizard_Horizontal 8128 LD A,E Test the sign of the X velocity.
8129 AND A
812A LD A,(IX+$00) Fetch the sprite ID of the player.
812D JP M,HandlerWizard_SetSprite Jump to HandlerWizard_SetSprite if the player is moving left.
8130 ADD A,$04 Add 04 to select the sprites for moving right.
8132 JR HandlerWizard_SetSprite Jump to HandlerWizard_SetSprite to set the sprite of the wizard.
Prev: 80CB Up: Map Next: 8134