![]() |
Routines |
| Prev: DB68 | Up: Map | Next: DC14 |
|
Used by the routine at UpdatePlayerLegs.
Works out the direction that the player is facing from the controls, which is held in bits 6 and 7 of the direction and timer of the player (0 is up the screen, 1 is right, 2 is down and 3 is left). A turn takes a few frames, which are counted in the lowest bits of the timer.
With the keyboard or when the option for directional control is not set, the controls for left and right turn the player. When it is set, the player turns towards the direction that the controls give, one quarter at a time, and moves when it faces that way.
|
||||||||||||||
|
Jump to SetFacingFlags while a turn is still counting.
|
||||||||||||||
| ChooseDirection | DB89 | LD A,(IX+$06) | Fetch the direction and the time left in a turn. | |||||||||||
| DB8C | AND %00000111 | Keep the time left in a turn. | ||||||||||||
| DB8E | JR Z,ChooseDirection_Controls | Jump to ChooseDirection_Controls if the player is not turning. | ||||||||||||
|
Count down the turn counter, and set the sprite of the player.
|
||||||||||||||
| DB90 | DEC (IX+$06) | Count down the time. | ||||||||||||
| DB93 | JR SetFacingFlags | Jump to SetFacingFlags. | ||||||||||||
|
Use the keyboard unless a joystick is set to give a direction.
|
||||||||||||||
| ChooseDirection_Controls | DB95 | LD HL,$BBB0 | Point HL at GameOptions. | |||||||||||
| DB98 | LD A,(HL) | Fetch GameOptions. | ||||||||||||
| DB99 | AND %00000110 | Keep the bits for the controls. | ||||||||||||
| DB9B | JR Z,ChooseDirection_Relative | Jump to ChooseDirection_Relative if the controls are the keyboard. | ||||||||||||
| DB9D | BIT 3,(HL) | Jump to ChooseDirection_Relative if the option for directional control is not set. | ||||||||||||
| DB9F | JR Z,ChooseDirection_Relative | |||||||||||||
|
Swap the controls for left and right, and up and down, if the view is rotated.
|
||||||||||||||
| DBA1 | LD A,($BBBA) | Fetch ViewRotatedFlag. | ||||||||||||
| DBA4 | AND %00000001 | Keep the lowest bit. | ||||||||||||
| DBA6 | CALL NZ,SwapControls | Call SwapControls if the view is rotated. | ||||||||||||
|
Turn towards the direction that is pressed.
|
||||||||||||||
| DBA9 | BIT 0,E | Jump to ChooseDirection_Right if the control for left is used. | ||||||||||||
| DBAB | JR NZ,ChooseDirection_Right | |||||||||||||
| DBAD | BIT 2,E | Jump to ChooseDirection_Up if the control for up is used. | ||||||||||||
| DBAF | JR NZ,ChooseDirection_Up | |||||||||||||
|
The controls are not for up.
|
||||||||||||||
| ChooseDirection_Right | DBB1 | BIT 1,E | Jump to ChooseDirection_WantRight if the control for right is used. | |||||||||||
| DBB3 | JR NZ,ChooseDirection_WantRight | |||||||||||||
| DBB5 | BIT 4,E | Jump to ChooseDirection_WantDown if the control for down is used. | ||||||||||||
| DBB7 | JR NZ,ChooseDirection_WantDown | |||||||||||||
| DBB9 | BIT 0,E | Jump to ChooseDirection_WantLeft if the control for left is used. | ||||||||||||
| DBBB | JR NZ,ChooseDirection_WantLeft | |||||||||||||
|
Clear the control for up, and return.
|
||||||||||||||
| DBBD | RES 2,E | Clear bit 2 of the controls. | ||||||||||||
| DBBF | RET | Return. | ||||||||||||
|
The controls are for up.
|
||||||||||||||
| ChooseDirection_Up | DBC0 | LD A,(IX+$06) | Fetch the direction of the player. | |||||||||||
|
How far is the heading from the direction that is wanted?
|
||||||||||||||
| ChooseDirection_Turn | DBC3 | AND %11000000 | Keep only the heading. | |||||||||||
| DBC5 | RES 2,E | Clear bit 2 of the controls. | ||||||||||||
| DBC7 | JR Z,ChooseDirection_Forward | Jump to ChooseDirection_Forward if the player already faces that way. | ||||||||||||
| DBC9 | CP $40 | Jump to ChooseDirection_TurnBack if the player has to turn back by a quarter. | ||||||||||||
| DBCB | JR Z,ChooseDirection_TurnBack | |||||||||||||
| DBCD | CP $C0 | Jump to ChooseDirection_TurnOn if the player has to turn on by a quarter. | ||||||||||||
| DBCF | JR Z,ChooseDirection_TurnOn | |||||||||||||
|
Choose which way to turn from the random seed, as the player has to turn right round.
|
||||||||||||||
| DBD1 | LD A,($BBAA) | Fetch the random seed. | ||||||||||||
| DBD4 | CP $80 | Jump to ChooseDirection_TurnOn if it is less than 80. | ||||||||||||
| DBD6 | JR C,ChooseDirection_TurnOn | |||||||||||||
|
Turn back a quarter.
|
||||||||||||||
| ChooseDirection_TurnBack | DBD8 | LD A,(IX+$06) | Fetch the direction of the player. | |||||||||||
| DBDB | SUB $40 | Take a quarter turn off it. | ||||||||||||
| DBDD | JR ChooseDirection_Counter | Jump to ChooseDirection_Counter. | ||||||||||||
|
Turn on a quarter.
|
||||||||||||||
| ChooseDirection_TurnOn | DBDF | LD A,(IX+$06) | Fetch the direction of the player. | |||||||||||
| DBE2 | ADD A,$40 | Add a quarter turn to it. | ||||||||||||
| DBE4 | JR ChooseDirection_Counter | Jump to ChooseDirection_Counter. | ||||||||||||
|
The controls are for right.
|
||||||||||||||
| ChooseDirection_WantRight | DBE6 | LD A,(IX+$06) | Fetch the direction of the player. | |||||||||||
| DBE9 | SUB $40 | Take a quarter turn off it. | ||||||||||||
| DBEB | JR ChooseDirection_Turn | Jump to ChooseDirection_Turn. | ||||||||||||
|
The controls are for down.
|
||||||||||||||
| ChooseDirection_WantDown | DBED | LD A,(IX+$06) | Fetch the direction of the player. | |||||||||||
| DBF0 | SUB $80 | Take two quarter turns off it. | ||||||||||||
| DBF2 | JR ChooseDirection_Turn | Jump to ChooseDirection_Turn. | ||||||||||||
|
The controls are for left.
|
||||||||||||||
| ChooseDirection_WantLeft | DBF4 | LD A,(IX+$06) | Fetch the direction of the player. | |||||||||||
| DBF7 | SUB $C0 | Take three quarter turns off it. | ||||||||||||
| DBF9 | JR ChooseDirection_Turn | Jump to ChooseDirection_Turn. | ||||||||||||
|
The player faces the way that was asked.
|
||||||||||||||
| ChooseDirection_Forward | DBFB | SET 2,E | Set the control for moving forward, and return. | |||||||||||
| DBFD | RET | |||||||||||||
|
Left and right turn the player a quarter.
|
||||||||||||||
| ChooseDirection_Relative | DBFE | LD A,(IX+$06) | Fetch the direction of the player. | |||||||||||
|
Turn the player back by a quarter if the control for left is used.
|
||||||||||||||
| DC01 | BIT 0,E | Jump to ChooseDirection_RelativeRight if left is not pressed. | ||||||||||||
| DC03 | JR Z,ChooseDirection_RelativeRight | |||||||||||||
| DC05 | SUB $40 | Take a quarter turn off the heading. | ||||||||||||
| DC07 | OR %00000001 | Start a turn. | ||||||||||||
|
Right turns the player the other way.
|
||||||||||||||
| ChooseDirection_RelativeRight | DC09 | BIT 1,E | Jump to ChooseDirection_Set if right is not pressed. | |||||||||||
| DC0B | JR Z,ChooseDirection_Set | |||||||||||||
| DC0D | ADD A,$40 | Add a quarter turn to the heading. | ||||||||||||
|
Start a turn and store the heading.
|
||||||||||||||
| ChooseDirection_Counter | DC0F | OR %00000001 | Start a turn. | |||||||||||
| ChooseDirection_Set | DC11 | LD (IX+$06),A | Set the direction of the player. | |||||||||||
|
Continue on to SetFacingFlags.
View the equivalent code in;
|
||||||||||||||
| Prev: DB68 | Up: Map | Next: DC14 |