Prev: 50339 Up: Map Next: 50540
50376: Handle Turning
Used by the routine at HandlePlayerLegs.
Turns the player to the left or the right, if the controls ask for it. A turn takes the player one quarter of the way round, and the player has to wait for two frames after that before it can turn again.
There is a second way of controlling the player, which is for use with a joystick and is chosen by bit 3 of the control method in ControlMethod. That bit is never set, so it is never used. In this way, four of the control bits stand for the four directions that the player can face, and the player turns until it faces the one that is asked for, and then walks.
Input
C Controls
IX Record of the legs
Output
C Controls, with the walking bit set
HandleTurning 50376 LD HL,42761 Take the control method, ControlMethod.
50379 LD A,(HL) Fetch the control method.
50380 AND %00000110 Keep only the bits that choose a joystick.
50382 JR Z,HandleTurning_Usual Jump to HandleTurning_Usual to turn the usual way if the keyboard is being used.
50384 BIT 3,(HL) Jump to HandleTurning_Usual to turn the usual way if bit 3 of the control method is not set.
50386 JR Z,HandleTurning_Usual
Turn towards the direction that is asked for. Return if the player has only just entered the room, or is not on the ground.
50388 LD A,(IX+12) Fetch the collision flags.
50391 AND %11110000 Keep only the countdown from entering the room.
50393 RET NZ Return if the player has only just entered the room.
50394 BIT 2,(IX+12) Return if the player is not on the ground.
50398 RET Z
50399 BIT 0,C Jump to HandleTurning_TestRight if the bit for turning left is set.
50401 JR NZ,HandleTurning_TestRight
50403 BIT 2,C Jump to HandleTurning_AskForward if the bit for walking forward is set.
50405 JR NZ,HandleTurning_AskForward
HandleTurning_TestRight 50407 BIT 1,C Jump to HandleTurning_AskRight if the bit for turning right is set.
50409 JR NZ,HandleTurning_AskRight
50411 BIT 4,C Jump to HandleTurning_AskPickUp if the bit for picking up and dropping is set.
50413 JR NZ,HandleTurning_AskPickUp
50415 BIT 0,C Jump to HandleTurning_AskLeft if the bit for turning left is set.
50417 JR NZ,HandleTurning_AskLeft
50419 RES 2,C Clear the bit for walking forward.
50421 RET Return.
Turn towards the direction that the bit for walking forward stands for, which is direction 2.
HandleTurning_AskForward 50422 CALL GetFacingDirection Call GetFacingDirection to find out which way the player is facing.
50425 CP 2 Compare it with the direction.
HandleTurning_Compare 50427 JR Z,HandleTurning_Walk Jump to HandleTurning_Walk to walk if the player is facing that way.
50429 CPL Work out which way to turn from the direction.
HandleTurning_Choose 50430 AND %00000001 Keep only one bit.
50432 JR HandleTurning_Turn Jump to HandleTurning_Turn to turn the player.
Turn towards the direction that the bit for turning right stands for, which is direction 1.
HandleTurning_AskRight 50434 CALL GetFacingDirection Call GetFacingDirection to find out which way the player is facing.
50437 CP 1 Compare it with the direction.
50439 JR HandleTurning_Compare Jump to HandleTurning_Compare to walk if the player is facing that way, and to turn if not.
Turn towards the direction that the bit for picking up and dropping stands for, which is direction 3.
HandleTurning_AskPickUp 50441 CALL GetFacingDirection Call GetFacingDirection to find out which way the player is facing.
50444 CP 3 Compare it with the direction.
HandleTurning_WalkIfEqual 50446 JR Z,HandleTurning_Walk Jump to HandleTurning_Walk to walk if the player is facing that way.
50448 JR HandleTurning_Choose Jump to HandleTurning_Choose to turn if not.
Turn towards the direction that the bit for turning left stands for, which is direction 0.
HandleTurning_AskLeft 50450 CALL GetFacingDirection Call GetFacingDirection to find out which way the player is facing.
50453 AND A Test the direction.
50454 JR HandleTurning_WalkIfEqual Jump to HandleTurning_WalkIfEqual to walk if the player is facing that way, and to turn if not.
HandleTurning_Walk 50456 SET 2,C Set the bit for walking forward.
50458 RET Return.
Turn the usual way. Wait first if the player has turned during the last two frames.
HandleTurning_Usual 50459 LD A,(IX+13) Fetch the hit flags, whose lowest three bits hold the time left before the player can turn.
50462 AND %00000111 Keep only the countdown.
50464 JR Z,HandleTurning_TestControls Jump to HandleTurning_TestControls if there is nothing left to wait for.
50466 DEC (IX+13) Take one off the countdown.
50469 RET Return.
HandleTurning_TestControls 50470 LD A,C Fetch the controls.
50471 AND %00000011 Keep only the bits for turning left and turning right.
50473 RET Z Return if neither is set.
50474 LD A,(IX+12) Fetch the collision flags.
50477 AND %11110000 Keep only the countdown from entering the room.
50479 RET NZ Return if the player has only just entered the room.
50480 BIT 3,(IX+12) Return if the player is jumping.
50484 RET NZ
50485 BIT 2,C Test the bit for walking forward, which makes no difference.
50487 JR NZ,HandleTurning_StartCountdown
HandleTurning_StartCountdown 50489 LD A,(IX+13) Fetch the hit flags.
50492 OR %00000010 Set bit 1 of them, to start the countdown that stops the player from turning again at once.
50494 LD (IX+13),A Set them.
50497 BIT 1,C Test the bit for turning right.
HandleTurning_Turn 50499 JR NZ,HandleTurning_Right Jump to HandleTurning_Right to turn right if it is set.
Turn left, which makes the direction go from 2 to 0, 3, 1 and back to 2. This is done by flipping the mirror flag of the legs, and the type as well if they were mirrored.
50501 BIT 6,(IX+7) Jump to HandleTurning_FlipMirror if the legs are not mirrored.
50505 JR Z,HandleTurning_FlipMirror
HandleTurning_FlipType 50507 LD A,(IX+0) Fetch the type of the legs.
50510 XOR %00000100 Flip bit 2 of it.
50512 LD (IX+0),A Write the flipped type of the legs.
HandleTurning_FlipMirror 50515 LD A,(IX+7) Fetch the flags.
50518 XOR %01000000 Flip the bit that mirrors the legs.
50520 LD (IX+7),A Set them.
50523 LD A,(IX+0) Set the type of the body to be eight more than the type of the legs.
50526 ADD A,8
50528 LD (IX+32),A
50531 RET Return.
Turn right, which makes the direction go from 2 to 1, 3, 0 and back to 2. This is done in the same way, but the type is flipped if the legs were not mirrored.
HandleTurning_Right 50532 BIT 6,(IX+7) Jump to HandleTurning_FlipType if the legs are not mirrored.
50536 JR Z,HandleTurning_FlipType
50538 JR HandleTurning_FlipMirror Jump to HandleTurning_FlipMirror.
View the equivalent code in;
Prev: 50339 Up: Map Next: 50540