Prev: 49431 Up: Map Next: 49597
49468: Handle Turning
Used by the routine at HandlePlayerLegs.
Turns the player to face the direction that was asked for. Where a joystick with directional control is in use the walk control is set when the player is already facing the direction that is pressed, and otherwise the player is turned. With the other methods of control the left and right controls turn the player. The routine returns early while the player is entering the room, jumping or not standing on something.
Turning starts by showing one of the sprites of objects 24 to 27 (see TurningRightSpriteTable and TurningLeftSpriteTable); HandleTurningLegs finishes the turn.
Input
C The controls
IX The address of the object
Output
C The controls, with the walk control changed
Use rotational control unless a joystick is directional.
HandleTurning 49468 LD HL,23300 Point HL at ControlMethod.
49471 LD A,(HL) Fetch it.
49472 AND %00000110 Keep only bits 1 and 2.
49474 JR Z,HandleTurning_Rotate Jump to HandleTurning_Rotate if they are zero.
49476 BIT 3,(HL) Jump to HandleTurning_Rotate if directional control is off.
49478 JR Z,HandleTurning_Rotate
Directional control. The player cannot turn while entering the room, or while it is not standing on something.
49480 LD A,(IX+12) Fetch the collision flags.
49483 AND %11110000 Keep only bits 4-7.
49485 RET NZ Return if the player is entering the room.
49486 BIT 2,(IX+12) Return if the player is in the air.
49490 RET Z
Find the direction that is pressed. Left (west) is tried before up (north). Down is bit 4 of the controls.
49491 BIT 0,C Jump to HandleTurning_Right if left is pressed.
49493 JR NZ,HandleTurning_Right
49495 BIT 2,C Jump to HandleTurning_North if up is pressed.
49497 JR NZ,HandleTurning_North
HandleTurning_Right 49499 BIT 1,C Jump to HandleTurning_East if right is pressed.
49501 JR NZ,HandleTurning_East
49503 BIT 4,C Jump to HandleTurning_South if down is pressed.
49505 JR NZ,HandleTurning_South
49507 BIT 0,C Jump to HandleTurning_West if left is pressed.
49509 JR NZ,HandleTurning_West
49511 RES 2,C Clear the walk control, as no direction is pressed.
49513 RET Return.
The facing of the player is 0 west, 1 east, 2 north and 3 south. If the player already faces the direction that is pressed, the walk control is set. Otherwise bit 0 of the direction (inverted for north and east) chooses which way to turn.
HandleTurning_North 49514 CALL GetFacingDirection Test whether the player is facing north.
49517 CP 2
HandleTurning_Facing 49519 JR Z,HandleTurning_Walk Jump to HandleTurning_Walk if it is.
49521 CPL Invert the direction.
HandleTurning_Turn 49522 AND %00000001 Keep bit 0, which decides which way to turn.
49524 JR HandleTurning_Start Jump to HandleTurning_Start.
HandleTurning_East 49526 CALL GetFacingDirection Test whether the player is facing east.
49529 CP 1
49531 JR HandleTurning_Facing Jump to HandleTurning_Facing.
HandleTurning_South 49533 CALL GetFacingDirection Test whether the player is facing south.
49536 CP 3
HandleTurning_TestFacing 49538 JR Z,HandleTurning_Walk Jump to HandleTurning_Walk if it is.
49540 JR HandleTurning_Turn Jump to HandleTurning_Turn.
HandleTurning_West 49542 CALL GetFacingDirection Test whether the player is facing west.
49545 AND A
49546 JR HandleTurning_TestFacing Jump to HandleTurning_TestFacing.
HandleTurning_Walk 49548 SET 2,C Set the walk control, as the player is facing the direction that is pressed.
49550 RET Return.
Rotational control. The player cannot turn while entering the room or while jumping.
HandleTurning_Rotate 49551 LD A,C Copy C to A.
49552 AND %00000011 Keep only bits 0 and 1.
49554 RET Z Return if they are zero.
49555 LD A,(IX+12) Fetch the collision flags.
49558 AND %11110000 Keep only bits 4-7.
49560 RET NZ Return if the player is entering the room.
49561 BIT 3,(IX+12) Return if the player is jumping.
49565 RET NZ
49566 BIT 1,C Test the right control.
HandleTurning_Start 49568 JR NZ,HandleTurning_TurnRight Jump to HandleTurning_TurnRight if the player is to turn right.
49570 RES 0,(IX+13) Reset bit 0 of the extra flags.
49574 LD HL,49626 Point HL at TurningLeftSpriteTable.
49577 JR HandleTurning_SetSprite Jump to HandleTurning_SetSprite.
HandleTurning_TurnRight 49579 SET 0,(IX+13) Set bit 0 of the extra flags.
49583 LD HL,49618 Point HL at TurningRightSpriteTable.
HandleTurning_SetSprite 49586 LD A,(IX+13) Fetch the extra flags.
49589 OR %00000010 Set bit 1.
49591 LD (IX+13),A Store the extra flags.
49594 CALL GetFacingDirection Call GetFacingDirection.
Continue on to SetSpriteFromTable.
View the equivalent code in;
Prev: 49431 Up: Map Next: 49597