Prev: 61710 Up: Map Next: 62154
62091: Handler: Spawn Helicopters
Used by the routine at RunHandlers.
Just return if the number of active helicopters is already at the maximum amount for this level.
Handler_SpawnHelicopters 62091 LD A,(53778) Return if *NumberActiveHelicopters is equal to *MaxHelicopterCount.
62094 LD B,A
62095 LD A,(54261)
62098 CP B
62099 RET Z
Add a hint of randomness to whether we proceed or not. Roughly 50% chance.
62100 CALL RandomNumber A=random number between 0-255.
62103 CP 128 Return if A is higher than 128.
62105 RET NC
Loop to find an empty slot.
62106 LD HL,53906 HL=53906 (Table_Helicopters-3).
Handler_SpawnHelicopters_FindSlot 62109 INC HL Move the table pointer to the next helicopter table data.
62110 INC HL
62111 INC HL
62112 LD A,(HL) Jump to Handler_SpawnHelicopters_FindSlot if this helicopter is already active.
62113 AND A
62114 JR NZ,Handler_SpawnHelicopters_FindSlot
50/50 chance of jumping to Handler_SpawnForegroundHelicopter.
62116 CALL RandomNumber Get a random number of either zero or one.
62119 AND %00000001
62121 JR Z,Handler_SpawnForegroundHelicopter Jump to Handler_SpawnForegroundHelicopter if the result is zero.
Creates a background helicopter.
62123 LD (HL),64 Write 64 (background) to helicopter state.
62125 INC HL Increment the helicopter table pointer by one.
62126 LD (HL),252 Write 252 to helicopter X position.
62128 JR Handler_Helicopter_SetYPos Jump to Handler_Helicopter_SetYPos.
Creates a foreground helicopter.
Handler_SpawnForegroundHelicopter 62130 LD (HL),128 Write 128 (foreground) to helicopter state.
62132 INC HL Increment the helicopter table pointer by one.
62133 LD (HL),36 Write 36 to helicopter X position.
Handler_Helicopter_SetYPos 62135 INC HL Increment the helicopter table pointer by one.
62136 LD (HL),3 Write 3 to helicopter Y position.
25% chance of jumping to Helicopter_Update_Count.
62138 CALL RandomNumber Get a random number between 0-3.
62141 AND %00000011
62143 JR Z,Helicopter_Update_Count Jump to Helicopter_Update_Count if the random number is 0.
62145 LD (HL),A Write the random number to helicopter Y position.
Keep track of the number of active helicopters.
Helicopter_Update_Count 62146 LD A,(54261) Increment *NumberActiveHelicopters by one.
62149 INC A
62150 LD (54261),A
62153 RET Return.
Prev: 61710 Up: Map Next: 62154