Prev: 8D6D Up: Map Next: 8DC4
8D77: Control Player
Used by the routines at HandlerWizard, HandlerSerf and HandlerKnight.
Moves the entity of a character, using the controls. Called by the handlers of the knight and the serf (and the wizard). The velocities of the entity are kept at offsets 06 (X) and 07 (Y), and have four bits after the point, so only the top four bits make up the whole pixels moved each frame. They are changed by UpdateVelocity, slowed by SlowVelocity and limited by CheckRoomBounds and CheckObstacles before ApplyMovement moves the entity. The bits at offset 02 are the number of steps still to be taken in the bottom four, and in bits 4-5 a flag that is set when movement is blocked along the X axis (bit 4) or the Y axis (bit 5).
Input
B The change made to a velocity each frame by the controls
C The fastest X velocity (the Y velocity is limited by B)
D The amount that the Y velocity is slowed by each frame
E The amount that the X velocity is slowed by each frame
IX The entity of the character
ControlPlayer 8D77 LD A,($EA91) Fetch the room of the player from PlayerRoom.
8D7A LD ($EE59),A Write A to EE59 (the room of the entity at Initialisation_Blank).
8D7D PUSH BC Stash the speed limits (BC), the slowing (DE) and HL on the stack.
8D7E PUSH DE
8D7F PUSH HL
8D80 CALL AutoWalkStep Call AutoWalkStep to take a step of the auto walk.
8D83 LD A,(IX+$02) Fetch offset 02 of the entity.
8D86 OR %00110000 Set bits 4-5, to stop all movement until a check shows it is possible.
8D88 LD (IX+$02),A Update offset 02 of the entity.
8D8B CALL StoreEntity Call StoreEntity to save the position of the entity.
Read the controls (a bit is zero when the control is used) and work out the change in velocity for each axis.
8D8E CALL ReadControls Call ReadControls to read the controls.
8D91 LD C,A Keep the controls in C.
8D92 POP HL Restore HL from the stack.
8D93 LD DE,$0000 DE=0000 (no change in either velocity).
8D96 BIT 1,C Jump to ControlPlayer_Right if bit 1 (left) is not used.
8D98 JR NZ,ControlPlayer_Right
8D9A LD A,B Fetch the change in velocity.
8D9B NEG Reverse the change, so that it is negative.
8D9D LD E,A E=A (the X change is -B).
ControlPlayer_Right 8D9E BIT 0,C Jump to ControlPlayer_Down if bit 0 (right) is not used.
8DA0 JR NZ,ControlPlayer_Down
8DA2 LD E,B E=B (the X change is B).
ControlPlayer_Down 8DA3 BIT 2,C Jump to ControlPlayer_Up if bit 2 (down) is not used.
8DA5 JR NZ,ControlPlayer_Up
8DA7 LD D,B D=B (the Y change is B).
ControlPlayer_Up 8DA8 BIT 3,C Jump to ControlPlayer_Move if bit 3 (up) is not used.
8DAA JR NZ,ControlPlayer_Move
8DAC LD A,B Fetch the change in velocity.
8DAD NEG Reverse the change, so that it is negative.
8DAF LD D,A D=A (the Y change is -B).
Slow the velocities, change them, check for obstacles and then move the entity.
ControlPlayer_Move 8DB0 POP HL Restore the amounts of slowing from the stack into HL.
8DB1 CALL SlowVelocity Call SlowVelocity to slow the entity down.
8DB4 POP HL Restore the fastest velocities from the stack into HL.
8DB5 CALL UpdateVelocity Call UpdateVelocity to update the velocities of the entity.
8DB8 CALL CheckRoomBounds Call CheckRoomBounds to check whether the entity is inside the room.
8DBB CALL CheckDoorway Call CheckDoorway to check the doorway.
8DBE CALL CheckObstacles Call CheckObstacles to check whether the entity would hit an item.
8DC1 JP ApplyMovement Jump to ApplyMovement to move the entity by its velocities.
Prev: 8D6D Up: Map Next: 8DC4