Prev: 27127 Up: Map Next: 27592
27382: Update Red Bird Movement
Used by the routine at Handler_RedBird.
Updates the red bird's position and animation. Handles the red bird's movement along its flight path, stun recovery, room transitions, and wing animation.
UpdateRedBirdMovement 27382 LD IX,56004 IX=Sprite01_3Wide_X_Position (red bird sprite data).
Reset the red bird's frame and colour to defaults.
27386 LD (IX+3),0 Write 0 to *IX+3 (clear frame/ set to invisible).
27390 LD (IX+2),2 Write RED to *IX+2.
If the red bird is stunned, handle stun recovery instead.
27394 LD A,(27828) Jump to UpdateRedBirdMovement_StunRecovery if *RedBirdStunTimer is set indicating the red bird is stunned.
27397 OR A
27398 JP NZ,UpdateRedBirdMovement_StunRecovery
If the room is being initialised, set a random appearance delay.
27401 LD A,(24507) Jump to UpdateRedBirdMovement_CheckDelay if *RespawnFlag is unset.
27404 OR A
27405 JR Z,UpdateRedBirdMovement_CheckDelay
27407 CALL GenerateRandomNumber Call GenerateRandomNumber.
27410 OR %00000001 Set bit 0 (ensure an odd value).
27412 AND %00111111 Keep only bits 0-5 (cap at 63).
27414 LD (27837),A Write A to *RedBirdAppearanceDelay.
If an appearance delay is active, the red bird is waiting to enter the current room so count down and handle the transition.
UpdateRedBirdMovement_CheckDelay 27417 LD A,(27837) Jump to UpdateRedBirdMovement_WaitToAppear if *RedBirdAppearanceDelay is active.
27420 OR A
27421 JR NZ,UpdateRedBirdMovement_WaitToAppear
Red bird is active in the current room so update its flight path.
27423 LD A,(24517) Write *CurrentRoom to *RedBirdCurrentRoom (store the red bird's current room).
27426 LD (27830),A
Decrement the direction change timer.
27429 LD HL,27826 HL=RedBirdDirectionChangeTimer.
27432 DEC (HL) Decrement *HL.
27433 JR NZ,UpdateRedBirdMovement_Move Jump to UpdateRedBirdMovement_Move if the timer hasn't expired.
Timer expired so choose a new flight direction.
27435 XOR A Write 0 to *RedBirdPathCounter.
27436 LD (27834),A
UpdateRedBirdMovement_0 27439 LD HL,27834 HL=RedBirdPathCounter.
27442 DEC (HL) Decrement *HL.
27443 CALL Z,HandleRedBird_SetupFlight Call HandleRedBird_SetupFlight if *HL reached zero (find a new flight path).
Pick a new random direction and duration.
27446 CALL GenerateRandomNumber Call GenerateRandomNumber.
27449 PUSH AF Stash AF on the stack.
27450 AND %00000111 Keep only bits 0-2 (random direction 0-7).
27452 LD (27832),A Write A to *RedBirdMovementDirection.
27455 POP AF Restore AF from the stack.
Calculate the direction change timer from the random value.
27456 RRCA Rotate right three positions.
27457 RRCA
27458 RRCA
27459 AND %01000000 Keep only bit 6.
27461 OR %00000100 Set bit 2.
27463 LD (27826),A Write A to *RedBirdDirectionChangeTimer.
Move the red bird in its current direction. The direction is doubled and self-modified into the jump table at Direction_Jump_Table.
UpdateRedBirdMovement_Move 27466 LD A,(27832) Load A with *RedBirdMovementDirection.
27469 ADD A,A Double it (each jump table entry is 2 bytes).
27470 LD (27593),A Write A to *27593 (self-modify the jump offset).
27473 LD C,(IX+0) C=*IX+0 (red bird's X position).
27476 LD B,(IX+1) B=*IX+1 (red bird's Y position).
27479 LD HL,27833 HL=RedBirdFlightSpeed.
27482 CALL Direction_Jump_Table Call Direction_Jump_Table.
27485 JR C,UpdateRedBirdMovement_0 Jump to UpdateRedBirdMovement_0 if the carry flag is set (red bird left the valid area).
Update the red bird's wing animation frame.
UpdateRedBirdMovement_Animate 27487 LD HL,27844 HL=RedBirdWingAnimationCounter.
27490 LD A,(HL) A=*HL.
27491 INC A Increment the animation counter.
27492 AND %00000111 Keep only bits 0-2 (cycle through 0-7).
27494 LD (HL),A Write back to *HL.
27495 RRA Rotate right (divide by 2).
27496 ADD A,24 A+=24 (red bird animation frame base).
27498 LD (56007),A Write A to *Sprite01_3Wide_Frame_ID (red bird frame).
27501 RET Return.
Red bird is waiting to appear. Count down the delay timer and handle the room transition when it expires.
UpdateRedBirdMovement_WaitToAppear 27502 LD A,(24517) B=*CurrentRoom.
27505 LD B,A
27506 LD A,(27830) A=*RedBirdCurrentRoom (red bird's current room).
27509 CP B Is the red bird in the same room as Percy?
27510 JR NZ,UpdateRedBirdMovement_Countdown Jump to UpdateRedBirdMovement_Countdown if not.
Red bird has arrived in Percy's room so clear the delay and animate.
27512 XOR A Write 0 to *RedBirdAppearanceDelay.
27513 LD (27837),A
27516 JR UpdateRedBirdMovement_Animate Jump to UpdateRedBirdMovement_Animate.
Still waiting so decrement the appearance delay.
UpdateRedBirdMovement_Countdown 27518 LD HL,27837 HL=RedBirdAppearanceDelay.
27521 DEC (HL) Decrement *HL.
27522 RET NZ Return if the delay hasn't expired yet.
Delay expired; determine which direction the red bird should enter from based on which room it's coming from relative to Percy's room.
27523 XOR A Write 0 to *RedBirdTraversalDirection (default: flying left).
27524 LD (27827),A
27527 LD A,(24517) B=*CurrentRoom.
27530 LD B,A
27531 LD A,(27830) A=*RedBirdCurrentRoom.
27534 CP B Jump to UpdateRedBirdMovement_EnterRoom if the red bird is coming from a lower numbered room.
27535 JR C,UpdateRedBirdMovement_EnterRoom
Red bird is coming from a higher room so enter flying right.
27537 LD A,1 Write 1 to *RedBirdTraversalDirection (flying right).
27539 LD (27827),A
UpdateRedBirdMovement_EnterRoom 27542 CALL HandleRedBird_SetupFlight Call HandleRedBird_SetupFlight.
27545 JR UpdateRedBirdMovement_Animate Jump to UpdateRedBirdMovement_Animate.
Handle the red bird's stun recovery. The stun timer counts down, and the red bird flashes blue while stunned. When the timer expires, the red bird becomes active again with a short appearance delay.
UpdateRedBirdMovement_StunRecovery 27547 LD HL,27828 HL=RedBirdStunTimer (stun timer).
27550 LD A,1 Write BLUE to *Sprite01_3Wide_Colour.
27552 LD (56006),A
27555 DEC (HL) Decrement the stun timer.
27556 LD A,(HL) A=*HL.
27557 CP 1 Jump to UpdateRedBirdMovement_StunEnd if the stun is about to end.
27559 JR Z,UpdateRedBirdMovement_StunEnd
Still stunned so only draw if the red bird is in the current room.
27561 LD A,(27830) B=*RedBirdCurrentRoom.
27564 LD B,A
27565 LD A,(24517) A=*CurrentRoom.
27568 CP B Return if the red bird is not in the same room as Percy.
27569 RET NZ
Red bird is stunned and visible so move it downward slowly (falling).
27570 LD C,(IX+0) C=*IX+0 (red bird's X position).
27573 LD A,(IX+1) A=*IX+1 (red bird's Y position).
27576 ADD A,3 A+=3 (drift downward).
27578 LD B,A Store the result in B.
27579 CALL Validate_Position Call Validate_Position.
27582 JR UpdateRedBirdMovement_Animate Jump to UpdateRedBirdMovement_Animate.
Stun ending so clear the timer and set a short reappearance delay.
UpdateRedBirdMovement_StunEnd 27584 DEC (HL) Clear the stun timer to 0.
Set a short reappearance delay.
27585 LD A,4 Write 4 to *RedBirdAppearanceDelay.
27587 LD (27837),A
27590 JR UpdateRedBirdMovement_WaitToAppear Jump to UpdateRedBirdMovement_WaitToAppear.
Prev: 27127 Up: Map Next: 27592