![]() |
Routines |
| Prev: 29715 | Up: Map | Next: 29863 |
|
Used by the routines at Handler_Room01, Handler_Room02, Handler_Room03, Handler_Room04, Handler_Room05, Handler_Room06, Handler_Room07, Handler_Room08, Handler_Room09, Handler_Room10 and Handler_Room11.
Controls the helicopter hazard movement and animation. Generates random direction changes and movement delays, moves the helicopter according to its current direction, and updates the animation frame. Used by all room handlers.
|
||||||||
|
Set up the helicopter data pointer and check if respawning is needed.
|
||||||||
| Handler_Helicopter | 29753 | LD IY,29960 | Point IY at Helicopter_State_Data_1. | |||||
|
This entry point is used by the routines at Handler_Room01 and Handler_Room06.
|
||||||||
| Handler_Helicopter_Entry | 29757 | LD A,(24507) | Call Randomise_Position_Loop if *RespawnFlag is set to randomise the helicopter's position. | |||||
| 29760 | OR A | |||||||
| 29761 | CALL NZ,Randomise_Position_Loop | |||||||
| 29764 | BIT 7,(IY+0) | Jump to Animate_Stunned_Hazard if bit 7 of *IY+0 is set (helicopter is spawning/inactive). | ||||||
| 29768 | JP NZ,Animate_Stunned_Hazard | |||||||
|
Decrement the movement delay timer; if it hasn't expired, skip ahead to move the helicopter in its current direction.
|
||||||||
| 29771 | DEC (IY+1) | Decrement the movement delay at *IY+1. | ||||||
| 29774 | JR NZ,Move_Helicopter | Jump to Move_Helicopter if the delay has not reached zero. | ||||||
|
Movement delay has expired; generate a new random direction and delay.
|
||||||||
| New_Random_Direction | 29776 | CALL Generate_Random_Number | Call Generate_Random_Number. | |||||
| 29779 | PUSH AF | Stash the random number on the stack. | ||||||
| 29780 | AND %00000111 | Mask and clear bit 0 to get an even direction value in the range 0-6. | ||||||
| 29782 | RES 0,A | |||||||
| 29784 | LD (IY+0),A | Write the result to *IY+0. | ||||||
| 29787 | POP AF | Restore the random number from the stack. | ||||||
| 29788 | RRCA | Rotate right three times, mask and set bit 0 to produce a delay of 1-63. | ||||||
| 29789 | RRCA | |||||||
| 29790 | RRCA | |||||||
| 29791 | AND %00111111 | |||||||
| 29793 | OR %00000001 | |||||||
| 29795 | LD (IY+1),A | Write the result to *IY+1. | ||||||
|
Move the helicopter in its current direction.
|
||||||||
| Move_Helicopter | 29798 | LD A,(IY+0) | Fetch the current direction from *IY+0 mask with 7 and double it to form a jump table index. | |||||
| 29801 | AND %00000111 | |||||||
| 29803 | ADD A,A | |||||||
| 29804 | LD (27593),A | Write the direction index to *27593. | ||||||
| 29807 | LD HL,29959 | Point HL at Helicopter_MovementBoundary (helicopter movement boundary data). | ||||||
| 29810 | LD C,(IX+0) | Load the helicopter's X position into C and Y position into B from *IX+0 and *IX+1. | ||||||
| 29813 | LD B,(IX+1) | |||||||
| 29816 | CALL Direction_Jump_Table | Call Direction_Jump_Table to move the helicopter in the current direction. | ||||||
| 29819 | JR C,New_Random_Direction | Jump to New_Random_Direction if the move was invalid (carry set) and pick a new random direction. | ||||||
|
Determine the facing direction based on the helicopter's position relative to Percy.
|
||||||||
| 29821 | LD A,(IX+0) | Jump to Update_Helicopter_Frame if the helicopter's X position with Percy's previous X position is equal. | ||||||
| 29824 | CP (IX+64) | |||||||
| 29827 | JR Z,Update_Helicopter_Frame | |||||||
| 29829 | LD (IY+3),0 | Set *IY+3 to 0 (facing left) if the helicopter is to the left of Percy; jump to Update_Helicopter_Frame. | ||||||
| 29833 | JR C,Update_Helicopter_Frame | |||||||
| 29835 | LD (IY+3),4 | Set *IY+3 to 4 (facing right) if the helicopter is to the right of Percy. | ||||||
|
Update the helicopter's animation frame.
|
||||||||
| Update_Helicopter_Frame | 29839 | LD A,(IY+4) | Increment the animation counter at *IY+4 wrapping at 3 to cycle through four frames. | |||||
| 29842 | INC A | |||||||
| 29843 | AND %00000011 | |||||||
| 29845 | LD (IY+4),A | Write the result to *IY+4. | ||||||
| 29848 | ADD A,46 | Calculate the sprite frame ID: add the immediate value (46) to the animation counter and the facing offset from *IY+3. | ||||||
| 29850 | ADD A,(IY+3) | |||||||
| 29853 | LD (IX+3),A | Write the sprite frame ID to *IX+3. | ||||||
| 29856 | LD (IX+2),1 | Set the sprite active flag at *IX+2 to 1. | ||||||
| 29860 | JP Check_Hazard_Collision | Jump to Check_Hazard_Collision. | ||||||
| Prev: 29715 | Up: Map | Next: 29863 |