Prev: 7413 Up: Map Next: 74A7
7439: Handler: Helicopter
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.
Input
IX Pointer to helicopter sprite data
Set up the helicopter data pointer and check if respawning is needed.
Handler_Helicopter 7439 LD IY,$7508 Point IY at Helicopter_State_Data_1.
This entry point is used by the routines at Handler_Room01 and Handler_Room06.
Handler_Helicopter_Entry 743D LD A,($5FBB) Call Randomise_Position_Loop if *RespawnFlag is set to randomise the helicopter's position.
7440 OR A
7441 CALL NZ,Randomise_Position_Loop
7444 BIT 7,(IY+$00) Jump to Animate_Stunned_Hazard if bit 7 of *IY+00 is set (helicopter is spawning/inactive).
7448 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.
744B DEC (IY+$01) Decrement the movement delay at *IY+01.
744E 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 7450 CALL Generate_Random_Number Call Generate_Random_Number.
7453 PUSH AF Stash the random number on the stack.
7454 AND %00000111 Mask and clear bit 0 to get an even direction value in the range 00-06.
7456 RES 0,A
7458 LD (IY+$00),A Write the result to *IY+00.
745B POP AF Restore the random number from the stack.
745C RRCA Rotate right three times, mask and set bit 0 to produce a delay of 01-3F.
745D RRCA
745E RRCA
745F AND %00111111
7461 OR %00000001
7463 LD (IY+$01),A Write the result to *IY+01.
Move the helicopter in its current direction.
Move_Helicopter 7466 LD A,(IY+$00) Fetch the current direction from *IY+00 mask with 07 and double it to form a jump table index.
7469 AND %00000111
746B ADD A,A
746C LD ($6BC9),A Write the direction index to *6BC9.
746F LD HL,$7507 Point HL at Helicopter_MovementBoundary (helicopter movement boundary data).
7472 LD C,(IX+$00) Load the helicopter's X position into C and Y position into B from *IX+00 and *IX+01.
7475 LD B,(IX+$01)
7478 CALL Direction_Jump_Table Call Direction_Jump_Table to move the helicopter in the current direction.
747B 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.
747D LD A,(IX+$00) Jump to Update_Helicopter_Frame if the helicopter's X position with Percy's previous X position is equal.
7480 CP (IX+$40)
7483 JR Z,Update_Helicopter_Frame
7485 LD (IY+$03),$00 Set *IY+03 to 00 (facing left) if the helicopter is to the left of Percy; jump to Update_Helicopter_Frame.
7489 JR C,Update_Helicopter_Frame
748B LD (IY+$03),$04 Set *IY+03 to 04 (facing right) if the helicopter is to the right of Percy.
Update the helicopter's animation frame.
Update_Helicopter_Frame 748F LD A,(IY+$04) Increment the animation counter at *IY+04 wrapping at 03 to cycle through four frames.
7492 INC A
7493 AND %00000011
7495 LD (IY+$04),A Write the result to *IY+04.
7498 ADD A,$2E Calculate the sprite frame ID: add the immediate value (2E) to the animation counter and the facing offset from *IY+03.
749A ADD A,(IY+$03)
749D LD (IX+$03),A Write the sprite frame ID to *IX+03.
74A0 LD (IX+$02),$01 Set the sprite active flag at *IX+02 to 01.
74A4 JP Check_Hazard_Collision Jump to Check_Hazard_Collision.
Prev: 7413 Up: Map Next: 74A7