Prev: 7892 Up: Map Next: 7924
7893: Handler: Walking Paratrooper
Used by the routines at Handler_Room05, Handler_Room06 and Handler_Room08.
Controls the paratrooper after landing. The paratrooper walks left and right along a platform, and will leap upward to try to catch Percy if he flies directly overhead. The paratrooper jumps up by 02 pixels per frame to a maximum height of 10 then drops back down to his platform. Walking speed and boundaries vary per room.
Input
IX Pointer to the paratrooper sprite data
Set up the paratrooper state pointer and movement parameters.
Handler_Walking_Paratrooper 7893 LD IY,$7B0D Point IY at Paratrooper_State_Data (paratrooper state data).
7897 LD HL,$7928 Point HL at Table_ParatrooperSpeed (per-room walking speed table).
789A LD A,($5FC5) Fetch the current room from *CurrentRoom, decrement to form a zero-based index and load the walking speed for this room into B.
789D DEC A
789E LD D,$00
78A0 LD E,A
78A1 ADD HL,DE
78A2 LD B,(HL)
78A3 LD HL,$7925 Point HL at Paratrooper_Direction_Flag (paratrooper movement boundary data).
Sprite ID Sprite
53 udg46459-56x4
78A6 LD C,$53 Set the base sprite frame in C to 53 (paratrooper walking right).
78A8 LD A,($5FC5) Fetch the current room from *CurrentRoom, decrement and multiply by 04 to index into the state data; add offset to IY.
78AB DEC A
78AC ADD A,A
78AD ADD A,A
78AE LD E,A
78AF LD D,$00
78B1 ADD IY,DE
Check if the paratrooper needs to reset after Percy respawns.
78B3 LD A,($5FBB) Skip to Check_Paratrooper_Leap_State if *RespawnFlag is unset.
78B6 OR A
78B7 JR Z,Check_Paratrooper_Leap_State
78B9 XOR A Write 00 to reset *Paratrooper_Leap_State (set the leap state to idle).
78BA LD ($7927),A
Check the current leap state to determine behaviour.
Check_Paratrooper_Leap_State 78BD LD A,($7927) Jump to Process_Paratrooper_Leap if *Paratrooper_Leap_State (leap state) is non-zero (already leaping).
78C0 OR A
78C1 JR NZ,Process_Paratrooper_Leap
Paratrooper is idle; check if Percy is flying directly overhead to trigger a leap.
78C3 LD A,($DAC0) Compare Percy's X position against the paratrooper's X position.
78C6 AND %11111100
78C8 LD E,A
78C9 LD A,(IX+$00)
78CC AND %11111100
78CE CP E
78CF JP NZ,Cat_Entry Jump to Cat_Entry if they don't match.
78D2 LD A,($DAC1) Jump to Cat_Entry if Percy's Y position is less than 28 (too high above) or greater than or equal to the paratrooper's Y position (Percy is not above the paratrooper).
78D5 CP $28
78D7 JP C,Cat_Entry
78DA CP (IX+$01)
78DD JP NC,Cat_Entry
78E0 XOR A Set A to 00 (begin new leap).
Process the leap movement based on the current state.
Process_Paratrooper_Leap 78E1 BIT 7,A Jump to Paratrooper_Descending if bit 7 of the leap state is set (paratrooper is descending back down).
78E3 JR NZ,Paratrooper_Descending
Paratrooper is leaping upward.
78E5 ADD A,$02 Add 02 to the leap state.
78E7 CP $10 Skip to Continue_Paratrooper_Leap if the leap state is still less than the maximum height (10).
78E9 JR NZ,Continue_Paratrooper_Leap
78EB SET 7,A Else the leap state has reached 10 (maximum height), set bit 7 to begin descending and jump to Store_Paratrooper_Leap_State.
78ED JR Store_Paratrooper_Leap_State
Continue_Paratrooper_Leap 78EF LD ($7927),A Write the updated leap state to *Paratrooper_Leap_State.
78F2 LD D,A Calculate the paratrooper's new Y position by subtracting the leap height from the platform Y position at *IY+01; write to *IX+01.
78F3 LD A,(IY+$01)
78F6 SUB D
78F7 LD (IX+$01),A
78FA JR Paratrooper_Walk_Or_Stunned Jump to Paratrooper_Walk_Or_Stunned.
Paratrooper is descending back to his platform.
Paratrooper_Descending 78FC LD E,A Copy the leap state into E.
78FD AND %01111111 Keep only bits 0-6.
78FF DEC A Decrease the descent counter by one.
7900 JR Z,Paratrooper_Leap_Complete Jump to Paratrooper_Leap_Complete if the descent counter has reached zero (back on platform).
7902 LD D,A Calculate the paratrooper's new Y position by subtracting the remaining height from the platform Y position; write to *IX+01.
7903 LD A,(IY+$01)
7906 SUB D
7907 LD (IX+$01),A
790A LD A,E Decrement the leap state and write it back to *Paratrooper_Leap_State.
790B DEC A
790C LD ($7927),A
790F JR Paratrooper_Walk_Or_Stunned Jump to Paratrooper_Walk_Or_Stunned.
Leap is complete; reset to idle.
Paratrooper_Leap_Complete 7911 XOR A Write 00 to *Paratrooper_Leap_State (return to idle state).
7912 LD ($7927),A
7915 JR Paratrooper_Walk_Or_Stunned Jump to Paratrooper_Walk_Or_Stunned.
Store_Paratrooper_Leap_State 7917 LD ($7927),A Write the leap state to *Paratrooper_Leap_State.
Resume the paratrooper's walking animation or handle stunned state.
Paratrooper_Walk_Or_Stunned 791A BIT 7,(IY+$00) Jump to Animate_Stunned_Hazard if bit 7 of *IY+00 is set (paratrooper is stunned by egg).
791E JP NZ,Animate_Stunned_Hazard
7921 JP Update_Cat_Frame Jump to Update_Cat_Frame to update the walking animation frame and check for collisions.
Prev: 7892 Up: Map Next: 7924