Prev: 69F7 Up: Map Next: 6BC8
6AF6: 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 6AF6 LD IX,$DAC4 IX=Sprite01_3Wide_X_Position (red bird sprite data).
Reset the red bird's frame and colour to defaults.
6AFA LD (IX+$03),$00 Write 00 to *IX+03 (clear frame/ set to invisible).
6AFE LD (IX+$02),$02 Write RED to *IX+02.
If the red bird is stunned, handle stun recovery instead.
6B02 LD A,($6CB4) Jump to UpdateRedBirdMovement_StunRecovery if *RedBirdStunTimer is set indicating the red bird is stunned.
6B05 OR A
6B06 JP NZ,UpdateRedBirdMovement_StunRecovery
If the room is being initialised, set a random appearance delay.
6B09 LD A,($5FBB) Jump to UpdateRedBirdMovement_CheckDelay if *RespawnFlag is unset.
6B0C OR A
6B0D JR Z,UpdateRedBirdMovement_CheckDelay
6B0F CALL GenerateRandomNumber Call GenerateRandomNumber.
6B12 OR %00000001 Set bit 0 (ensure an odd value).
6B14 AND %00111111 Keep only bits 0-5 (cap at 3F).
6B16 LD ($6CBD),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 6B19 LD A,($6CBD) Jump to UpdateRedBirdMovement_WaitToAppear if *RedBirdAppearanceDelay is active.
6B1C OR A
6B1D JR NZ,UpdateRedBirdMovement_WaitToAppear
Red bird is active in the current room so update its flight path.
6B1F LD A,($5FC5) Write *CurrentRoom to *RedBirdCurrentRoom (store the red bird's current room).
6B22 LD ($6CB6),A
Decrement the direction change timer.
6B25 LD HL,$6CB2 HL=RedBirdDirectionChangeTimer.
6B28 DEC (HL) Decrement *HL.
6B29 JR NZ,UpdateRedBirdMovement_Move Jump to UpdateRedBirdMovement_Move if the timer hasn't expired.
Timer expired so choose a new flight direction.
6B2B XOR A Write 00 to *RedBirdPathCounter.
6B2C LD ($6CBA),A
UpdateRedBirdMovement_0 6B2F LD HL,$6CBA HL=RedBirdPathCounter.
6B32 DEC (HL) Decrement *HL.
6B33 CALL Z,HandleRedBird_SetupFlight Call HandleRedBird_SetupFlight if *HL reached zero (find a new flight path).
Pick a new random direction and duration.
6B36 CALL GenerateRandomNumber Call GenerateRandomNumber.
6B39 PUSH AF Stash AF on the stack.
6B3A AND %00000111 Keep only bits 0-2 (random direction 00-07).
6B3C LD ($6CB8),A Write A to *RedBirdMovementDirection.
6B3F POP AF Restore AF from the stack.
Calculate the direction change timer from the random value.
6B40 RRCA Rotate right three positions.
6B41 RRCA
6B42 RRCA
6B43 AND %01000000 Keep only bit 6.
6B45 OR %00000100 Set bit 2.
6B47 LD ($6CB2),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 6B4A LD A,($6CB8) Load A with *RedBirdMovementDirection.
6B4D ADD A,A Double it (each jump table entry is 02 bytes).
6B4E LD ($6BC9),A Write A to *6BC9 (self-modify the jump offset).
6B51 LD C,(IX+$00) C=*IX+00 (red bird's X position).
6B54 LD B,(IX+$01) B=*IX+01 (red bird's Y position).
6B57 LD HL,$6CB9 HL=RedBirdFlightSpeed.
6B5A CALL Direction_Jump_Table Call Direction_Jump_Table.
6B5D 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 6B5F LD HL,$6CC4 HL=RedBirdWingAnimationCounter.
6B62 LD A,(HL) A=*HL.
6B63 INC A Increment the animation counter.
6B64 AND %00000111 Keep only bits 0-2 (cycle through 00-07).
6B66 LD (HL),A Write back to *HL.
6B67 RRA Rotate right (divide by 02).
6B68 ADD A,$18 A+=18 (red bird animation frame base).
6B6A LD ($DAC7),A Write A to *Sprite01_3Wide_Frame_ID (red bird frame).
6B6D RET Return.
Red bird is waiting to appear. Count down the delay timer and handle the room transition when it expires.
UpdateRedBirdMovement_WaitToAppear 6B6E LD A,($5FC5) B=*CurrentRoom.
6B71 LD B,A
6B72 LD A,($6CB6) A=*RedBirdCurrentRoom (red bird's current room).
6B75 CP B Is the red bird in the same room as Percy?
6B76 JR NZ,UpdateRedBirdMovement_Countdown Jump to UpdateRedBirdMovement_Countdown if not.
Red bird has arrived in Percy's room so clear the delay and animate.
6B78 XOR A Write 00 to *RedBirdAppearanceDelay.
6B79 LD ($6CBD),A
6B7C JR UpdateRedBirdMovement_Animate Jump to UpdateRedBirdMovement_Animate.
Still waiting so decrement the appearance delay.
UpdateRedBirdMovement_Countdown 6B7E LD HL,$6CBD HL=RedBirdAppearanceDelay.
6B81 DEC (HL) Decrement *HL.
6B82 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.
6B83 XOR A Write 00 to *RedBirdTraversalDirection (default: flying left).
6B84 LD ($6CB3),A
6B87 LD A,($5FC5) B=*CurrentRoom.
6B8A LD B,A
6B8B LD A,($6CB6) A=*RedBirdCurrentRoom.
6B8E CP B Jump to UpdateRedBirdMovement_EnterRoom if the red bird is coming from a lower numbered room.
6B8F JR C,UpdateRedBirdMovement_EnterRoom
Red bird is coming from a higher room so enter flying right.
6B91 LD A,$01 Write 01 to *RedBirdTraversalDirection (flying right).
6B93 LD ($6CB3),A
UpdateRedBirdMovement_EnterRoom 6B96 CALL HandleRedBird_SetupFlight Call HandleRedBird_SetupFlight.
6B99 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 6B9B LD HL,$6CB4 HL=RedBirdStunTimer (stun timer).
6B9E LD A,$01 Write BLUE to *Sprite01_3Wide_Colour.
6BA0 LD ($DAC6),A
6BA3 DEC (HL) Decrement the stun timer.
6BA4 LD A,(HL) A=*HL.
6BA5 CP $01 Jump to UpdateRedBirdMovement_StunEnd if the stun is about to end.
6BA7 JR Z,UpdateRedBirdMovement_StunEnd
Still stunned so only draw if the red bird is in the current room.
6BA9 LD A,($6CB6) B=*RedBirdCurrentRoom.
6BAC LD B,A
6BAD LD A,($5FC5) A=*CurrentRoom.
6BB0 CP B Return if the red bird is not in the same room as Percy.
6BB1 RET NZ
Red bird is stunned and visible so move it downward slowly (falling).
6BB2 LD C,(IX+$00) C=*IX+00 (red bird's X position).
6BB5 LD A,(IX+$01) A=*IX+01 (red bird's Y position).
6BB8 ADD A,$03 A+=03 (drift downward).
6BBA LD B,A Store the result in B.
6BBB CALL Validate_Position Call Validate_Position.
6BBE JR UpdateRedBirdMovement_Animate Jump to UpdateRedBirdMovement_Animate.
Stun ending so clear the timer and set a short reappearance delay.
UpdateRedBirdMovement_StunEnd 6BC0 DEC (HL) Clear the stun timer to 00.
Set a short reappearance delay.
6BC1 LD A,$04 Write 04 to *RedBirdAppearanceDelay.
6BC3 LD ($6CBD),A
6BC6 JR UpdateRedBirdMovement_WaitToAppear Jump to UpdateRedBirdMovement_WaitToAppear.
Prev: 69F7 Up: Map Next: 6BC8