Prev: 77B4 Up: Map Next: 7891
77B9: Handler: Balloon
Controls the balloon hazard. The balloon floats horizontally across the screen, randomly changing direction at the edges and occasionally bobbing up and down. When hit by Percy's egg, it pops through a deflating animation before respawning.
Input
IX Pointer to the balloon sprite data
Handler_Balloon 77B9 LD A,($5FBB) Jump to Respawn_Balloon if *RespawnFlag is set.
77BC OR A
77BD JP NZ,Respawn_Balloon
77C0 LD HL,$7891 Point HL at Balloon_Direction_Flag.
77C3 LD A,($7892) Jump to Balloon_Popping if *Balloon_Pop_Counter is set.
77C6 OR A
77C7 JP NZ,Balloon_Popping
Balloon is active; randomly toggle the float direction.
77CA LD A,R Use the Memory Refresh Register masked to a number between 00-80.
77CC AND %01111111
77CE CP $7F Jump to Move_Balloon if the result is not equal to 7F.
77D0 JR NZ,Move_Balloon
77D2 LD A,(HL) Toggle the direction flag at *HL by complementing and writing back.
77D3 CPL
77D4 LD (HL),A
Move the balloon horizontally based on its direction.
Move_Balloon 77D5 LD A,(HL) Jump to Balloon_Float_Left if the direction flag is non-zero (set to floating left).
77D6 OR A
77D7 JR NZ,Balloon_Float_Left
Floating right: increment X position.
77D9 LD A,(IX+$00) Fetch the balloon X position from *IX+00.
77DC ADD A,$01 Add 01.
77DE CP $EE Jump to Balloon_Reverse_Left if the balloon X position has reached EE (off-screen right; reverse direction).
77E0 JR NC,Balloon_Reverse_Left
77E2 LD (IX+$00),A Write the updated X position to *IX+00.
77E5 JR Adjust_Balloon_Altitude Jump to Adjust_Balloon_Altitude.
Floating left: decrement X position.
Balloon_Float_Left 77E7 LD A,(IX+$00) Fetch the balloon X position from *IX+00.
77EA SUB $01 Subtract 01.
77EC CP $04 Jump to Balloon_Reverse_Right if the balloon X position has dropped below 04 (off-screen left; reverse direction).
77EE JR C,Balloon_Reverse_Right
77F0 LD (IX+$00),A Write the updated X position to *IX+00.
Randomly adjust the balloon's altitude to create a bobbing effect.
Adjust_Balloon_Altitude 77F3 CALL Generate_Random_Number Call Generate_Random_Number.
77F6 AND %00000011 Keep only bits 0-1.
77F8 CP $03 Jump to Set_Balloon_Frame if not equal to 03 (only adjust altitude on a 1-in-4 chance).
77FA JR NZ,Set_Balloon_Frame
77FC LD A,R Load B with the Memory Refresh Register.
77FE LD B,A
77FF BIT 6,A Jump to Balloon_Bob_Up if bit 6 is set (move upward).
7801 JR NZ,Balloon_Bob_Up
Bob downward.
7803 LD A,B Mask B to get a step of 00 or 01.
7804 AND %00000001
7806 ADD A,(IX+$01) Add to the balloon Y position.
7809 CP $70 Jump to Set_Balloon_Frame if the balloon Y position has reached 70 (maximum altitude, don't go lower).
780B JR NC,Set_Balloon_Frame
780D LD (IX+$01),A Write the updated balloon Y position back to *IX+01.
7810 JR Set_Balloon_Frame Jump to Set_Balloon_Frame.
Bob upward.
Balloon_Bob_Up 7812 LD A,B Mask B to get a step of 00 or 01.
7813 AND %00000001
7815 LD B,A
7816 LD A,(IX+$01) Fetch the balloon Y position from *IX+01.
7819 SUB B Subtract the step.
781A CP $18 Jump to Set_Balloon_Frame if the balloon Y position has dropped below 18 (minimum altitude, don't go higher).
781C JR C,Set_Balloon_Frame
781E LD (IX+$01),A Write the updated balloon Y position back to *IX+01.
Set the balloon frame and check for collisions.
Sprite ID Sprite
49 udg46139-56x4
Set_Balloon_Frame 7821 LD (IX+$03),$49 Write 49 to *IX+03 (balloon frame).
7825 LD IY,$DAC0 Point IY at Percy_X_Position (Percy sprite data).
7829 CALL CheckSpriteCollision Call CheckSpriteCollision to check for collision with Percy.
782C JR C,Check_Balloon_Egg Jump to Check_Balloon_Egg if there's been no collision.
782E JP Hazard_Hit_Percy Jump to Hazard_Hit_Percy to register the hit on Percy.
No collision with Percy; check if Percy's egg hits the balloon.
Check_Balloon_Egg 7831 LD A,($5FA9) Return if *EggDropFlag is unset.
7834 OR A
7835 RET Z
7836 LD IY,$DAE0 Point IY at Egg_X_Position (egg sprite data).
783A CALL CheckEggCollision Call CheckEggCollision to check for egg collision with the balloon.
783D RET C Return if there's been no collision with the balloon.
783E LD A,$01 Write 01 to start/ activate *Balloon_Pop_Counter.
7840 LD ($7892),A
7843 JP Stun_Hazard_And_Score Jump to Stun_Hazard_And_Score to stun the balloon and award points.
7846 RET Return.
Balloon reached the right edge; reverse direction to float left.
Balloon_Reverse_Left 7847 LD (HL),$FF Write FF to *HL (set direction to floating left).
7849 JR Set_Balloon_Frame Jump to Set_Balloon_Frame.
Balloon reached the left edge; reverse direction to float right.
Balloon_Reverse_Right 784B LD (HL),$00 Write 00 to *HL (set direction to floating right).
784D JR Set_Balloon_Frame Jump to Set_Balloon_Frame.
Respawn the balloon after Percy respawns.
Respawn_Balloon 784F LD A,$B9 Write B9 to *Balloon_Pop_Counter (set a long respawn delay).
7851 LD ($7892),A
7854 RET Return.
Balloon popping animation is in progress.
Balloon_Popping 7855 LD HL,$7892 Point HL at Balloon_Pop_Counter.
7858 LD A,(HL) Fetch the current counter value.
7859 CP $04 Jump to Balloon_Respawn_Delay if the counter is 04 or more (still in the delay phase).
785B JR NC,Balloon_Respawn_Delay
Popping animation phase: cycle through deflating frames.
Sprite ID Sprite
4A udg46171-56x4
4B udg46203-56x4
4C udg46235-56x4
785D INC A Increment the counter and write back.
785E LD (HL),A
785F ADD A,$48 Add 48 to calculate the deflating frame.
7861 LD (IX+$03),A Write the frame to *IX+03.
7864 CALL Generate_Random_Number Call Generate_Random_Number.
7867 AND %00000111 Mask for a random flicker value.
7869 LD (IX+$02),A Write to *IX+02 (sprite active flag, for flicker).
786C CALL PlayHitSound Call PlayHitSound.
786F RET Return.
Respawn delay phase: wait until the counter reaches C8 before respawning.
Balloon_Respawn_Delay 7870 INC A Increment the counter and write back.
7871 LD (HL),A
7872 CP $C8 Return if the counter has not reached C8 (still waiting).
7874 RET NZ
Respawn the balloon at a random horizontal position.
7875 LD (IX+$01),$38 Write 38 to *IX+01 (reset Y position).
7879 LD (IX+$02),$07 Write 07 to *IX+02 (reset sprite active flag).
787D LD HL,$7892 Point HL at Balloon_Pop_Counter.
7880 LD (HL),$00 Write 00 to *HL (clear the counter).
7882 LD (IX+$00),$EE Write EE to *IX+00 (spawn from the right).
7886 CALL Generate_Random_Number Call Generate_Random_Number.
7889 BIT 0,A Return if bit 0 is not set (50% chance to spawn from the right).
788B RET Z
788C LD (IX+$00),$04 Write 04 to *IX+00 (spawn from the left instead).
7890 RET Return.
Prev: 77B4 Up: Map Next: 7891