Prev: 30336 Up: Map Next: 30483
30348: Handle Plane
Used by the routine at Handler_Plane.
Controls the plane hazard. The plane flies horizontally across the screen and can drop a bomb on Percy when directly above. The plane has two flight directions and its speed varies by room. On room 3 the boundaries are adjusted. When the plane reaches the screen edge it deactivates and waits for a random trigger to respawn from the opposite side.
Input
IX Pointer to the plane sprite data
Set up the plane state pointer and room-specific parameters.
Handle_Plane 30348 LD IY,30639 Point IY at Plane_State_Data.
30352 LD C,4 Set the left boundary to 4 in C.
30354 LD B,56 Set the right boundary to 56 in B.
30356 LD A,(24517) Jump to Plane_Check_Respawn if *CurrentRoom is not equal to 3.
30359 CP 3
30361 JR NZ,Plane_Check_Respawn
30363 LD C,64 Set the left boundary to 64 in C.
30365 LD B,C Copy to B (both boundaries are 64 on room 3).
Plane_Check_Respawn 30366 LD A,(24507) Jump to Spawn_Plane if *RespawnFlag is set.
30369 OR A
30370 JP NZ,Spawn_Plane
30373 LD A,(IY+2) Jump to Plane_Wait_To_Spawn if *IY+2 (plane active flag) is zero (waiting to spawn).
30376 OR A
30377 JR Z,Plane_Wait_To_Spawn
30379 BIT 7,(IY+0) Jump to Animate_Stunned_Hazard if bit 7 of *IY+0 is set (plane is stunned by egg).
30383 JP NZ,Animate_Stunned_Hazard
Plane is active; move it horizontally based on flight direction.
30386 LD HL,30643 Point HL at Plane_Speed.
30389 LD A,(IX+0) Fetch the plane X position from *IX+0.
30392 BIT 7,(IY+1) Test bit 7 of *IY+1 (flight direction); jump to Plane_Flying_Left if set (flying left).
30396 JR NZ,Plane_Flying_Left
Flying right: add the speed to the X position.
30398 ADD A,(HL) Add the speed from *HL.
30399 CP 238 Jump to Plane_Off_Screen if the X position has reached 238 (off-screen right).
30401 JR NC,Plane_Off_Screen
30403 LD (IX+0),A Write the updated X position to *IX+0.
30406 JR Set_Plane_Frame Jump to Set_Plane_Frame.
Flying left: subtract the speed from the X position.
Plane_Flying_Left 30408 SUB (HL) Subtract the speed from *HL.
30409 CP C Jump to Plane_Off_Screen if the X position has dropped below C (off-screen left).
30410 JR C,Plane_Off_Screen
30412 LD (IX+0),A Write the updated X position to *IX+0.
Set the plane's sprite frame based on flight direction.
Sprite ID Sprite
77 udg46267-56x4
Set_Plane_Frame 30415 LD A,77 Set A to 77 (plane flying left frame).
30417 BIT 7,(IY+1) Jump to Store_Plane_Frame if bit 7 of *IY+1 is set (flying left).
30421 JR NZ,Store_Plane_Frame
Sprite ID Sprite
78 udg46299-56x4
30423 INC A Increment to 78 (plane flying right frame).
Store_Plane_Frame 30424 LD (IX+3),A Write the frame to *IX+3.
30427 JP Check_Hazard_Collision Jump to Check_Hazard_Collision to check for collision with Percy or egg.
Plane is inactive; randomly trigger a respawn.
Plane_Wait_To_Spawn 30430 LD A,R Use the Memory Refresh Register masked as a random value.
30432 AND %01111111
30434 CP 127 Return if the value is not equal to 127 (wait for random trigger).
30436 RET NZ
Spawn the plane: reset all state and pick a random starting side.
Spawn_Plane 30437 SET 7,(IY+2) Set bit 7 of *IY+2 (mark plane as active).
30441 XOR A Write 0 to;
  • *Bomb_Explosion_Counter
  • *IY+3 (bomb active flag)
  • *IY+1 (flight direction)
  • *IX+0 (X position)
  • *IX+2 (sprite active flag)
  • *IX+1 (Y position)
  • *IY+0 (stunned flag)
30442 LD (30638),A
30445 LD (IY+3),A
30448 LD (IY+1),A
30451 LD (IX+0),C
30454 LD (IX+2),A
30457 LD (IX+1),B
30460 LD (IY+0),A
30463 LD A,R Use the Memory Refresh Register masked to randomly pick a starting side.
30465 AND %00000001
30467 RET Z Return if bit 0 is not set (spawn from the left at X=0).
30468 LD (IX+0),238 Write 238 to *IX+0 (spawn from the right).
30472 SET 7,(IY+1) Set bit 7 of *IY+1 (set flight direction to left).
30476 RET Return.
Plane has flown off-screen; deactivate and return to waiting state.
Plane_Off_Screen 30477 LD (IY+2),0 Write 0 to *IY+2 (mark plane as inactive).
30481 JR Plane_Wait_To_Spawn Jump to Plane_Wait_To_Spawn.
Prev: 30336 Up: Map Next: 30483