Prev: 7597 Up: Map Next: 7628
759A: Handler: UFO
Controls the UFO hazard. The UFO wanders randomly around the screen and attempts to abduct Percy. When it catches Percy, it teleports him to the UFO's position, plays a tractor beam sound effect, then drops him downward. The UFO cannot be stunned by Percy's egg, but a hit will cancel the egg.
Input
IX Pointer to the UFO sprite data
Check for respawn.
Handler_UFO 759A LD A,($5FBB) Call Reset_UFO_Position if *RespawnFlag is set to reset the UFO.
759D OR A
759E CALL NZ,Reset_UFO_Position
Decrement the movement delay timer.
75A1 LD HL,$7679 Decrement *UFO_Movement_Delay.
75A4 DEC (HL)
75A5 JR NZ,Move_UFO Jump to Move_UFO if *UFO_Movement_Delay hasn't reached zero.
Movement delay expired; generate new random direction and delay.
New_UFO_Direction 75A7 CALL Generate_Random_Number Call Generate_Random_Number to generate a random number.
75AA LD HL,$7679 Point HL at UFO_Movement_Delay (UFO movement delay).
75AD PUSH AF Stash the random value on the stack.
75AE AND %00000111 Keep only bits 0-2.
75B0 INC HL Increment HL by one to UFO_Direction.
75B1 LD (HL),A Write A to *HL to set the new direction.
75B2 DEC HL Move HL back to UFO_Movement_Delay.
75B3 POP AF Restore the random value from the stack.
75B4 RRCA Rotate the random value right three times.
75B5 RRCA
75B6 RRCA
75B7 AND %00011111 Keep only bits 0-4.
75B9 OR %00000100 Set bit 2 to produce a delay.
75BB LD (HL),A Write A to *UFO_Movement_Delay.
75BC PUSH HL Stash the UFO state data pointer on the stack.
Set a random value for the UFO speed between 01-03.
Generate_UFO_Speed 75BD CALL Generate_Random_Number Call Generate_Random_Number.
75C0 AND %00000011 Keep only bits 0-1 to limit the random number to between 00-03.
75C2 OR A Jump back to Generate_UFO_Speed to try again if the speed is zero.
75C3 JR Z,Generate_UFO_Speed
75C5 LD ($767B),A Write the random speed to *UFO_Speed.
75C8 POP HL Restore the UFO state data pointer from the stack.
Move the UFO in its current direction.
Move_UFO 75C9 INC HL Load the direction from *HL+01 mask and double to form a jump table index.
75CA LD A,(HL)
75CB AND %00000111
75CD ADD A,A
75CE LD ($6BC9),A Write the direction index to *6BC9.
75D1 LD HL,$767B Point HL at UFO_Speed.
75D4 LD C,(IX+$00) Load the UFO's X position into C and Y position into B from *IX+00 and *IX+01.
75D7 LD B,(IX+$01)
75DA CALL Direction_Jump_Table Call Direction_Jump_Table to move the UFO in the current direction.
75DD JR C,New_UFO_Direction Jump to New_UFO_Direction if the move was invalid (carry set) and pick a new direction.
Update the UFO's animation frame, wrapping at 03.
75DF LD HL,$767C Point HL at UFO_Animation_Counter.
75E2 LD A,(HL) Increment the animation counter, skip to Set_UFO_Frame if it's not yet at frame 03.
75E3 INC A
75E4 CP $03
75E6 JR NZ,Set_UFO_Frame
75E8 XOR A Reset the frame back to 00.
Set_UFO_Frame 75E9 LD (HL),A Write the UFO frame to *UFO_Animation_Counter.
Sprite ID Sprite
4F udg46331-56x4
75EA ADD A,$4F Add 4F as the base UFO frame and write it to *IX+03.
75EC LD (IX+$03),A
75EF LD A,($767D) Toggle the sprite flicker flag at *UFO_Flicker_Flag between 00 and 01.
75F2 INC A
75F3 AND %00000001
75F5 LD ($767D),A
75F8 INC A Write 01 to *IX+02 (sprite active value).
75F9 LD (IX+$02),A
Check if the UFO has recently abducted Percy.
75FC LD A,($767E) Jump to Check_UFO_Percy if *UFO_Abduction_Timer is zero.
75FF OR A
7600 JR Z,Check_UFO_Percy
7602 DEC A Decrement the abduction timer and write it back to *UFO_Abduction_Timer.
7603 LD ($767E),A
7606 JR UFO_Abduct_Percy Jump to UFO_Abduct_Percy.
Check for collision with Percy.
Check_UFO_Percy 7608 LD IY,$DAC0 Point IY at Percy_X_Position (Percy sprite data).
760C CALL CheckSpriteCollision Call CheckSpriteCollision to check for collision with Percy.
760F JR C,Check_UFO_Egg Jump to Check_UFO_Egg if carry is set (no collision).
UFO has caught Percy; set the abduction timer.
7611 LD A,$64 Set 64 as the *UFO_Abduction_Timer value.
7613 LD ($767E),A
7616 RET Return.
No collision with Percy; check if Percy's egg hits the UFO.
Check_UFO_Egg 7617 LD A,($5FA9) Return if *EggDropFlag is unset.
761A OR A
761B RET Z
761C LD IY,$DAE0 Point IY at Egg_X_Position (egg sprite data).
7620 CALL CheckEggCollision Call CheckEggCollision to check for egg collision with the UFO.
7623 RET C Return if carry is set (no collision).
7624 CALL CancelEggDrop Call CancelEggDrop.
7627 RET Return.
Prev: 7597 Up: Map Next: 7628