Prev: 30644 Up: Map Next: 30865
30649: 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 30649 LD A,(24507) Jump to Respawn_Balloon if *RespawnFlag is set.
30652 OR A
30653 JP NZ,Respawn_Balloon
30656 LD HL,30865 Point HL at Balloon_Direction_Flag.
30659 LD A,(30866) Jump to Balloon_Popping if *Balloon_Pop_Counter is set.
30662 OR A
30663 JP NZ,Balloon_Popping
Balloon is active; randomly toggle the float direction.
30666 LD A,R Use the Memory Refresh Register masked to a number between 0-128.
30668 AND %01111111
30670 CP 127 Jump to Move_Balloon if the result is not equal to 127.
30672 JR NZ,Move_Balloon
30674 LD A,(HL) Toggle the direction flag at *HL by complementing and writing back.
30675 CPL
30676 LD (HL),A
Move the balloon horizontally based on its direction.
Move_Balloon 30677 LD A,(HL) Jump to Balloon_Float_Left if the direction flag is non-zero (set to floating left).
30678 OR A
30679 JR NZ,Balloon_Float_Left
Floating right: increment X position.
30681 LD A,(IX+0) Fetch the balloon X position from *IX+0.
30684 ADD A,1 Add 1.
30686 CP 238 Jump to Balloon_Reverse_Left if the balloon X position has reached 238 (off-screen right; reverse direction).
30688 JR NC,Balloon_Reverse_Left
30690 LD (IX+0),A Write the updated X position to *IX+0.
30693 JR Adjust_Balloon_Altitude Jump to Adjust_Balloon_Altitude.
Floating left: decrement X position.
Balloon_Float_Left 30695 LD A,(IX+0) Fetch the balloon X position from *IX+0.
30698 SUB 1 Subtract 1.
30700 CP 4 Jump to Balloon_Reverse_Right if the balloon X position has dropped below 4 (off-screen left; reverse direction).
30702 JR C,Balloon_Reverse_Right
30704 LD (IX+0),A Write the updated X position to *IX+0.
Randomly adjust the balloon's altitude to create a bobbing effect.
Adjust_Balloon_Altitude 30707 CALL Generate_Random_Number Call Generate_Random_Number.
30710 AND %00000011 Keep only bits 0-1.
30712 CP 3 Jump to Set_Balloon_Frame if not equal to 3 (only adjust altitude on a 1-in-4 chance).
30714 JR NZ,Set_Balloon_Frame
30716 LD A,R Load B with the Memory Refresh Register.
30718 LD B,A
30719 BIT 6,A Jump to Balloon_Bob_Up if bit 6 is set (move upward).
30721 JR NZ,Balloon_Bob_Up
Bob downward.
30723 LD A,B Mask B to get a step of 0 or 1.
30724 AND %00000001
30726 ADD A,(IX+1) Add to the balloon Y position.
30729 CP 112 Jump to Set_Balloon_Frame if the balloon Y position has reached 112 (maximum altitude, don't go lower).
30731 JR NC,Set_Balloon_Frame
30733 LD (IX+1),A Write the updated balloon Y position back to *IX+1.
30736 JR Set_Balloon_Frame Jump to Set_Balloon_Frame.
Bob upward.
Balloon_Bob_Up 30738 LD A,B Mask B to get a step of 0 or 1.
30739 AND %00000001
30741 LD B,A
30742 LD A,(IX+1) Fetch the balloon Y position from *IX+1.
30745 SUB B Subtract the step.
30746 CP 24 Jump to Set_Balloon_Frame if the balloon Y position has dropped below 24 (minimum altitude, don't go higher).
30748 JR C,Set_Balloon_Frame
30750 LD (IX+1),A Write the updated balloon Y position back to *IX+1.
Set the balloon frame and check for collisions.
Sprite ID Sprite
73 udg46139-56x4
Set_Balloon_Frame 30753 LD (IX+3),73 Write 73 to *IX+3 (balloon frame).
30757 LD IY,56000 Point IY at Percy_X_Position (Percy sprite data).
30761 CALL CheckSpriteCollision Call CheckSpriteCollision to check for collision with Percy.
30764 JR C,Check_Balloon_Egg Jump to Check_Balloon_Egg if there's been no collision.
30766 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 30769 LD A,(24489) Return if *EggDropFlag is unset.
30772 OR A
30773 RET Z
30774 LD IY,56032 Point IY at Egg_X_Position (egg sprite data).
30778 CALL CheckEggCollision Call CheckEggCollision to check for egg collision with the balloon.
30781 RET C Return if there's been no collision with the balloon.
30782 LD A,1 Write 1 to start/ activate *Balloon_Pop_Counter.
30784 LD (30866),A
30787 JP Stun_Hazard_And_Score Jump to Stun_Hazard_And_Score to stun the balloon and award points.
30790 RET Return.
Balloon reached the right edge; reverse direction to float left.
Balloon_Reverse_Left 30791 LD (HL),255 Write 255 to *HL (set direction to floating left).
30793 JR Set_Balloon_Frame Jump to Set_Balloon_Frame.
Balloon reached the left edge; reverse direction to float right.
Balloon_Reverse_Right 30795 LD (HL),0 Write 0 to *HL (set direction to floating right).
30797 JR Set_Balloon_Frame Jump to Set_Balloon_Frame.
Respawn the balloon after Percy respawns.
Respawn_Balloon 30799 LD A,185 Write 185 to *Balloon_Pop_Counter (set a long respawn delay).
30801 LD (30866),A
30804 RET Return.
Balloon popping animation is in progress.
Balloon_Popping 30805 LD HL,30866 Point HL at Balloon_Pop_Counter.
30808 LD A,(HL) Fetch the current counter value.
30809 CP 4 Jump to Balloon_Respawn_Delay if the counter is 4 or more (still in the delay phase).
30811 JR NC,Balloon_Respawn_Delay
Popping animation phase: cycle through deflating frames.
Sprite ID Sprite
74 udg46171-56x4
75 udg46203-56x4
76 udg46235-56x4
30813 INC A Increment the counter and write back.
30814 LD (HL),A
30815 ADD A,72 Add 72 to calculate the deflating frame.
30817 LD (IX+3),A Write the frame to *IX+3.
30820 CALL Generate_Random_Number Call Generate_Random_Number.
30823 AND %00000111 Mask for a random flicker value.
30825 LD (IX+2),A Write to *IX+2 (sprite active flag, for flicker).
30828 CALL PlayHitSound Call PlayHitSound.
30831 RET Return.
Respawn delay phase: wait until the counter reaches 200 before respawning.
Balloon_Respawn_Delay 30832 INC A Increment the counter and write back.
30833 LD (HL),A
30834 CP 200 Return if the counter has not reached 200 (still waiting).
30836 RET NZ
Respawn the balloon at a random horizontal position.
30837 LD (IX+1),56 Write 56 to *IX+1 (reset Y position).
30841 LD (IX+2),7 Write 7 to *IX+2 (reset sprite active flag).
30845 LD HL,30866 Point HL at Balloon_Pop_Counter.
30848 LD (HL),0 Write 0 to *HL (clear the counter).
30850 LD (IX+0),238 Write 238 to *IX+0 (spawn from the right).
30854 CALL Generate_Random_Number Call Generate_Random_Number.
30857 BIT 0,A Return if bit 0 is not set (50% chance to spawn from the right).
30859 RET Z
30860 LD (IX+0),4 Write 4 to *IX+0 (spawn from the left instead).
30864 RET Return.
Prev: 30644 Up: Map Next: 30865