Prev: 31185 Up: Map Next: 31427
31186: Handler: Parachute Descent
Used by the routines at Handler_Room02, Handler_Room08 and Handler_Room09.
Controls the paratrooper's parachute descent. The paratrooper descends under a parachute canopy, and upon reaching the bottom boundary the parachute folds up and detaches, drifting sideways while the paratrooper separates. The bottom boundary varies by room, and on room 8 it is extended to 136. Uses two sprite entries: the canopy (*IX+0 to *IX+3) and the body (*IX+4 to *IX+7).
Input
IX Pointer to the parachute sprite data
Set up initial state and check for respawn.
Handler_Parachute_Descent 31186 LD A,(24507) Fetch the respawn flag from *RespawnFlag.
31189 LD B,112 Set the default bottom boundary to 112 in B.
31191 LD IY,31427 Point IY at Parachute_State_Data.
31195 OR A Jump to Reset_Parachute if the respawn flag is non-zero (reset the parachute).
31196 JP NZ,Reset_Parachute
31199 LD A,(24517) If *CurrentRoom is not equal to 8 skip over setting it below.
31202 CP 8
31204 JR NZ,Check_Parachute_State
31206 LD B,136 Set the bottom boundary to 136.
Check the parachute's current state.
Check_Parachute_State 31208 BIT 7,(IY+0) Jump to Parachute_Stunned if bit 7 of *IY+0 is set (parachute is stunned by egg).
31212 JP NZ,Parachute_Stunned
31215 LD A,(IY+1) Jump to Animate_Parachute_Fold if *IY+1 (landing counter) is non-zero (parachute is folding).
31218 OR A
31219 JR NZ,Animate_Parachute_Fold
31221 LD A,(IY+2) Jump to Parachute_Detach if *IY+2 (detach flag) is non-zero (parachute has detached).
31224 OR A
31225 JR NZ,Parachute_Detach
Descent phase: move the paratrooper downward by 2 pixels per frame.
Parachute_Descend 31227 LD A,(IX+1) Load A with the canopy Y position from *IX+1.
31230 ADD A,2 Add 2 to the canopy Y position.
31232 CP B Jump to Begin_Parachute_Fold if the canopy Y position has reached the bottom boundary in B.
31233 JR NC,Begin_Parachute_Fold
31235 LD (IX+1),A Write the updated Y position to *IX+1 (canopy Y).
31238 ADD A,16 Set the body Y position to the canopy Y plus 16.
31240 LD (IX+5),A
31243 LD (IX+3),91 Set the canopy sprite frame to 91 (open parachute).
Set_Body_Frame_And_Check 31247 LD (IX+7),82 Set the body sprite frame to 82 (paratrooper under parachute).
31251 CALL Check_Hazard_Collision Call Check_Hazard_Collision to check for collision with Percy or egg (canopy sprite).
31254 INC IX Advance IX by four to the body sprite entry.
31256 INC IX
31258 INC IX
31260 INC IX
31262 JP Check_Hazard_Collision Jump to Check_Hazard_Collision to check for collision with Percy or egg (body sprite).
Paratrooper has reached the bottom boundary; begin folding the parachute.
Begin_Parachute_Fold 31265 LD A,1 Set the landing counter to 1.
31267 LD (IY+1),A Write the counter to *IY+1.
Animate_Parachute_Fold 31270 CP 7 Jump to Continue_Fold if the landing counter has not reached 7.
31272 JR NZ,Continue_Fold
31274 LD (IY+1),0 Reset the landing counter to 0 and set the detach flag at *IY+2 to 1 (parachute fully folded).
31278 LD (IY+2),1
31282 JR Parachute_Detach Jump to Parachute_Detach.
Continue_Fold 31284 INC A Increment the landing counter and write it back to *IY+1.
31285 LD (IY+1),A
31288 SRL A Divide by two and add 91 to calculate the folding parachute frame.
31290 ADD A,91
31292 LD (IX+3),A Write the frame to *IX+3 (canopy sprite).
31295 JR Set_Body_Frame_And_Check Jump to Set_Body_Frame_And_Check to set the body frame and check for collisions.
Detach phase: the parachute drifts sideways while the paratrooper separates.
Parachute_Detach 31297 LD A,(IY+3) Increment the animation counter at *IY+3 wrapping at 7.
31300 INC A
31301 AND %00000111
31303 LD (IY+3),A
31306 SRL A Divide by two and add 87 to calculate the drifting paratrooper walking frame.
31308 ADD A,87
31310 LD (IX+7),A Write the frame to *IX+7 (body sprite frame).
31313 LD A,(IX+4) Load A with the body X position from *IX+4.
31316 CP 128 If the body X position is less than 128 it is drifting left; jump to Drift_Right if drifting right.
31318 JR NC,Drift_Right
Drifting left: subtract 2 from the body X position.
Drift_Left 31320 SUB 2 Subtract 2 from the X position.
31322 CP 4 Jump to Reset_Parachute if it has gone below 4 (off-screen to the left).
31324 JR C,Reset_Parachute
31326 LD (IX+4),A Write the updated X position to *IX+4 (body X).
31329 JP Check_Hazard_Collision Jump to Check_Hazard_Collision to check for collision with Percy or egg.
Drifting right: add 2 to the body X position.
Drift_Right 31332 ADD A,2 Add 2 to the body X position.
31334 CP 238 Jump to Reset_Parachute if the body X position has reached 238 (off-screen to the right).
31336 JR NC,Reset_Parachute
31338 LD (IX+4),A Write the updated X position to *IX+4 (body X).
31341 LD A,(IX+7) Subtract 4 from the body sprite frame to get the opposite facing walking frame.
31344 SUB 4
31346 LD (IX+7),A
31349 INC IX Advance IX by four to the body sprite entry.
31351 INC IX
31353 INC IX
31355 INC IX
31357 JP Check_Hazard_Collision Jump to Check_Hazard_Collision to check for collision with Percy or egg.
Parachute has been stunned by Percy's egg; animate the stunned state.
Parachute_Stunned 31360 LD A,(IY+3) Jump to Animate_Stunned_Body if *IY+3 is non-zero (skip canopy animation).
31363 OR A
31364 JR NZ,Animate_Stunned_Body
31366 CALL Animate_Stunned_Hazard Call Animate_Stunned_Hazard to animate the stunned canopy.
31369 INC IX Advance IX by four to the body sprite entry.
31371 INC IX
31373 INC IX
31375 INC IX
Animate_Stunned_Body 31377 JP Animate_Stunned_Hazard Jump to Animate_Stunned_Hazard to animate the stunned body.
Reset the parachute to its starting position for this room.
Reset_Parachute 31380 LD A,(24517) Look up the starting X position for the current room from the table at Table_ParachuteXPosition and write to both the canopy (*IX+0) and body (*IX+4) X positions.
31383 DEC A
31384 LD E,A
31385 LD D,0
31387 LD HL,31492
31390 ADD HL,DE
31391 LD A,(HL)
31392 LD (IX+0),A
31395 LD (IX+4),A
31398 LD A,4 Set both Y positions: canopy to 4 body to 20.
31400 LD (IX+1),A
31403 ADD A,16
31405 LD (IX+5),A
31408 LD (IX+2),7 Set both sprite active flags to 7.
31412 LD (IX+6),7
31416 XOR A Write 0 to *IY+0 *IY+1 and *IY+2 to clear the stunned flag, landing counter and detach flag.
31417 LD (IY+0),A
31420 LD (IY+1),A
31423 LD (IY+2),A
31426 RET Return.
Prev: 31185 Up: Map Next: 31427