Prev: 51322 Up: Map Next: 51528
51359: Handle Turning
Used by the routine at HandlePlayerLegs.
Turns the player, using the left and right controls or, if a joystick with directional control is in use, the direction that is pressed. The directional controls turn the player a quarter turn at a time towards the direction pressed along the shortest way, and flag the player to walk once it is facing that direction. The facing of the player is stored as the horizontal flip flag and bit 3 of the graphic number.
Input
C The controls
IX Address of the object
Output
C The controls, with the walk control changed if directional control is in use
HandleTurning 51359 LD HL,23460 Fetch the control method, ControlMethod.
51362 LD A,(HL)
51363 AND %00000110 Keep the joystick bits.
51365 JR Z,HandleTurning_Rotate Jump to HandleTurning_Rotate if the keyboard is in use.
51367 BIT 3,(HL) Jump to HandleTurning_Rotate if directional control is not in use.
51369 JR Z,HandleTurning_Rotate
Directional control. The player cannot turn while entering the room, or while it is not standing on something.
51371 LD A,(IX+12) Fetch the flags of the player.
51374 AND %11110000 Keep the counter of the player entering the room.
51376 RET NZ Return if the player is entering the room.
51377 BIT 2,(IX+12) Test whether the player is standing on something.
51381 RET Z Return if it is not.
Find the direction that is pressed. Left takes priority over up.
51382 BIT 0,C Jump to HandleTurning_Right if it is pressed.
51384 JR NZ,HandleTurning_Right
51386 BIT 2,C Jump to HandleTurning_North if it is pressed.
51388 JR NZ,HandleTurning_North
HandleTurning_Right 51390 BIT 1,C Jump to HandleTurning_East if it is pressed.
51392 JR NZ,HandleTurning_East
51394 BIT 4,C Jump to HandleTurning_South if it is pressed.
51396 JR NZ,HandleTurning_South
51398 BIT 0,C Jump to HandleTurning_West if it is pressed.
51400 JR NZ,HandleTurning_West
51402 RES 2,C Clear the walk control, as no direction is pressed.
51404 RET Return.
The facing of the player is 0 for west, 1 for east, 2 for north and 3 for south.
HandleTurning_North 51405 CALL GetFacingDirection Fetch the direction the player is facing.
51408 CP 2 Test whether it is north.
HandleTurning_North_Test 51410 JR Z,HandleTurning_Walk Jump to HandleTurning_Walk if it is.
51412 CPL Invert the direction.
HandleTurning_North_Direction 51413 AND %00000001 Keep bit 0, which decides which way to turn.
51415 JR HandleTurning_Turn Jump to HandleTurning_Turn.
HandleTurning_East 51417 CALL GetFacingDirection Fetch the direction the player is facing.
51420 CP 1 Test whether it is east.
51422 JR HandleTurning_North_Test Jump to HandleTurning_North_Test.
HandleTurning_South 51424 CALL GetFacingDirection Fetch the direction the player is facing.
51427 CP 3 Test whether it is south.
HandleTurning_South_Test 51429 JR Z,HandleTurning_Walk Jump to HandleTurning_Walk if it is.
51431 JR HandleTurning_North_Direction Jump to HandleTurning_North_Direction.
HandleTurning_West 51433 CALL GetFacingDirection Fetch the direction the player is facing.
51436 AND A Test whether it is west.
51437 JR HandleTurning_South_Test Jump to HandleTurning_South_Test.
HandleTurning_Walk 51439 SET 2,C Set the walk control, as the player is facing the direction that is pressed.
51441 RET Return.
Rotational control. After each turn the player has to wait before it can turn again.
HandleTurning_Rotate 51442 LD A,(IX+13) Fetch the flags.
51445 AND %00000111 Keep the turning delay counter, which is in the low three bits.
51447 JR Z,HandleTurning_Rotate_ReadControls Jump to HandleTurning_Rotate_ReadControls if it has run out.
51449 DEC (IX+13) Count it down.
51452 RET Return.
HandleTurning_Rotate_ReadControls 51453 LD A,C Fetch the controls.
51454 AND %00000011 Keep left and right.
51456 RET Z Return if neither is pressed.
51457 LD A,(IX+12) Fetch the flags of the player.
51460 AND %11110000 Keep the counter of the player entering the room.
51462 RET NZ Return if the player is entering the room.
51463 BIT 3,(IX+12) Test whether the player is jumping.
51467 RET NZ Return if it is.
51468 BIT 2,C Jump to HandleTurning_Rotate_Reset if it is pressed.
51470 JR NZ,HandleTurning_Rotate_Reset
51472 PUSH BC Stash the controls on the stack.
51473 CALL PlayFootstepsSound_EveryFrame Play the sound of the footsteps.
51476 POP BC Restore the controls from the stack.
HandleTurning_Rotate_Reset 51477 LD A,(IX+13) Fetch the flags.
51480 OR %00000010 Set the turning delay counter, which has run out, to 2.
51482 LD (IX+13),A Store it.
51485 BIT 1,C Test the right control.
HandleTurning_Turn 51487 JR NZ,HandleTurning_ToggleFlip_Test Jump to HandleTurning_ToggleFlip_Test if the player is to turn right.
51489 BIT 6,(IX+7) Jump to HandleTurning_ToggleFlip if the sprite is flipped horizontally.
51493 JR NZ,HandleTurning_ToggleFlip
HandleTurning_ToggleGraphic 51495 LD A,(IX+0) Fetch the graphic number.
51498 XOR %00001000 Toggle bit 3 of it.
51500 LD (IX+0),A Store it.
HandleTurning_ToggleFlip 51503 LD A,(IX+7) Fetch the flags.
51506 XOR %01000000 Toggle the horizontal flip flag.
51508 LD (IX+7),A Store the flags.
51511 LD A,(IX+0) Fetch the graphic number, and add 16 to get the top half.
51514 ADD A,16
51516 LD (IX+32),A Set the graphic number of the top half of the player.
51519 RET Return.
HandleTurning_ToggleFlip_Test 51520 BIT 6,(IX+7) Jump to HandleTurning_ToggleGraphic if the sprite is flipped horizontally.
51524 JR NZ,HandleTurning_ToggleGraphic
51526 JR HandleTurning_ToggleFlip Jump to HandleTurning_ToggleFlip.
View the equivalent code in;
Prev: 51322 Up: Map Next: 51528