Prev: 9654 Up: Map Next: 9884
970E: Handler: Mr Magnetic Brella
Count the alien and steer it toward the scroll position at Jetman_Position. When it is close to the object at World_Slot_1_Position, it picks that object up and carries it.
Input
IX Actor slot
Handler_MrMagneticBrella 970E LD HL,$5E5E HL=AlienCount.
9711 INC (HL) Increase AlienCount by one.
9712 BIT 0,(IX+$08) Jump to Handler_MrMagneticBrella_AttachedFly if the alien is already attached.
9716 JP NZ,Handler_MrMagneticBrella_AttachedFly
Attach when the alien is close to World_Slot_1_Position.
9719 LD A,($60B0) Jump to Handler_MrMagneticBrella_CopyBeside if World_Slot_1_Flags is already set.
971C AND A
971D JR NZ,Handler_MrMagneticBrella_CopyBeside
Test whether the alien is horizontally close to the object.
971F LD H,(IX+$03) Fetch the high byte of the world X.
9722 LD L,(IX+$02) Fetch the low byte of the world X.
9725 LD DE,($60AA) Fetch World_Slot_1_Position.
9729 LD BC,$0008 Add an 08 tolerance.
972C ADD HL,BC
972D SBC HL,DE Subtract the target position.
972F LD A,H Fetch the high byte of the gap.
9730 AND %00011111 Keep only bits 0-4.
9732 JR NZ,Handler_MrMagneticBrella_CopyBeside Jump to Handler_MrMagneticBrella_CopyBeside if they are not on the same screen.
9734 LD A,L Fetch the low byte of the gap.
9735 CP $10 Jump to Handler_MrMagneticBrella_CopyBeside if it is at least 10.
9737 JR NC,Handler_MrMagneticBrella_CopyBeside
Test whether the alien is vertically close to the object.
9739 LD A,($60AC) Fetch World_Slot_1_Y.
973C SUB (IX+$04) Subtract the alien's Y position.
973F CP $10 Jump to Handler_MrMagneticBrella_CopyBeside if the Y gap is at least 10.
9741 JR NC,Handler_MrMagneticBrella_CopyBeside
Flag both the alien and the object as attached.
9743 SET 0,(IX+$08) Set bit 0 of the actor flags.
9747 LD HL,$60B0 HL=World_Slot_1_Flags.
974A SET 0,(HL) Set bit 0 of the target flags.
Copy the position at World_Slot_1_Position to the alien if it is beside World_Slot_2_Position.
Handler_MrMagneticBrella_CopyBeside 974C CALL TestAlienBesideSlot Jump to Handler_MrMagneticBrella_ApplyDownThrust if the alien is not beside World_Slot_2_Position.
974F JR NZ,Handler_MrMagneticBrella_ApplyDownThrust
9751 LD DE,($60AA) Fetch World_Slot_1_Position.
9755 LD (IX+$03),D Copy that position into the alien's world X.
9758 LD (IX+$02),E
975B LD A,($60AC) Fetch World_Slot_1_Y.
975E LD (IX+$04),A Copy it to the alien's Y position.
Apply downward thrust and update the Y position.
Handler_MrMagneticBrella_ApplyDownThrust 9761 LD A,(IX+$06) Jump to Handler_MrMagneticBrella_AddThrust if the vertical thrust is negative.
9764 AND A
9765 JP M,Handler_MrMagneticBrella_AddThrust
9768 CP $30 Jump to Handler_MrMagneticBrella_AddThrustToY if the thrust is already at least 30.
976A JR NC,Handler_MrMagneticBrella_AddThrustToY
Handler_MrMagneticBrella_AddThrust 976C ADD A,$02 Add 02 to the thrust.
976E LD (IX+$06),A Write the thrust back.
Handler_MrMagneticBrella_AddThrustToY 9771 SRA A Divide the thrust by 10.
9773 SRA A
9775 SRA A
9777 SRA A
9779 ADD A,(IX+$04) Add it to the alien's Y position.
977C CP $B0 Jump to Handler_MrMagneticBrella_BounceGround if the alien has hit the ground line.
977E JR NC,Handler_MrMagneticBrella_BounceGround
Handler_MrMagneticBrella_WriteY 9780 LD (IX+$04),A Write the Y position back.
Steer toward the scroll, then animate.
Handler_MrMagneticBrella_Loop 9783 LD H,(IX+$03) Fetch the high byte of the world X.
9786 LD L,(IX+$02) Fetch the low byte of the world X.
9789 PUSH HL Stash the world X on the stack.
978A LD DE,($607A) Fetch Jetman_Position.
978E SBC HL,DE Subtract the scroll position.
9790 LD C,$00 C=00.
Leave the speed unchanged if the alien is on this screen or just off its left edge.
9792 LD A,H Fetch the high byte of the gap.
9793 AND %00011111 Keep only bits 0-4.
9795 JR Z,Handler_MrMagneticBrella_RestoreX Jump to Handler_MrMagneticBrella_RestoreX if the alien is on this screen.
9797 OR %11100000 Set bits 5-7.
9799 CPL Flip the bits.
979A AND A Jump to Handler_MrMagneticBrella_RestoreX if the result is zero.
979B JR Z,Handler_MrMagneticBrella_RestoreX
979D BIT 4,H Test bit 4 of the gap.
30 is a signed +30 rightward speed; D0 is signed -30 leftward.
979F LD A,$30 A=30.
97A1 JR NZ,Handler_MrMagneticBrella_WriteSpeed Jump to Handler_MrMagneticBrella_WriteSpeed if the alien is left of the scroll.
97A3 LD A,$D0 A=D0.
Handler_MrMagneticBrella_WriteSpeed 97A5 LD (IX+$05),A Write the speed to *IX+05.
Move the carried object with the alien if it is attached.
Handler_MrMagneticBrella_RestoreX 97A8 POP HL Restore the world X from the stack.
97A9 BIT 0,(IX+$08) Jump to Handler_MrMagneticBrella_TickAnimation if the alien is not attached.
97AD JP Z,Handler_MrMagneticBrella_TickAnimation
97B0 LD ($60AA),HL Write the world X back to World_Slot_1_Position.
97B3 LD A,(IX+$04) Fetch the alien's Y position.
97B6 ADD A,$1A Add 1A.
97B8 CP $B0 Jump to Handler_MrMagneticBrella_WriteLinkedY if it is still above the ground line.
97BA JR C,Handler_MrMagneticBrella_WriteLinkedY
AF is the ground line.
97BC LD A,$AF A=AF.
Handler_MrMagneticBrella_WriteLinkedY 97BE LD ($60AC),A Write it to World_Slot_1_Y.
Animate the alien and set its colour.
Handler_MrMagneticBrella_TickAnimation 97C1 INC (IX+$11) Increase the animation timer.
97C4 LD A,(IX+$11) Fetch the animation timer.
97C7 AND %00000111 Keep only bits 0-2.
Sprite IDs begin at 40 ("Mr Magnetic Brella: Frame 1").
97C9 ADD A,$40 Add 40 for the seeking frames.
97CB LD (IX+$00),A Write it to the actor type.
97CE BIT 0,(IX+$10) Jump to Handler_MrMagneticBrella_SetColour if bit 0 of *IX+10 is reset.
97D2 JR Z,Handler_MrMagneticBrella_SetColour
97D4 BIT 0,(IX+$08) Jump to Handler_MrMagneticBrella_SetColour if the alien is not attached.
97D8 JR Z,Handler_MrMagneticBrella_SetColour
97DA LD A,$80 Write 80 to World_Slot_1_Flags.
97DC LD ($60B0),A
Handler_MrMagneticBrella_SetColour 97DF LD (IX+$07),$45 Write INK:CYAN, PAPER:BLACK (BRIGHT) to the actor colour.
97E3 JP PlaceSpawnedAlien_Age Jump to PlaceSpawnedAlien_Age.
Bounce off the ground line.
Handler_MrMagneticBrella_BounceGround 97E6 LD A,(IX+$06) Jump to Handler_MrMagneticBrella_WriteY if the vertical thrust is negative.
97E9 AND A
97EA JP M,Handler_MrMagneticBrella_WriteY
97ED NEG Negate the thrust.
97EF LD (IX+$06),A Write it back.
97F2 JR Handler_MrMagneticBrella_Loop Jump to Handler_MrMagneticBrella_Loop.
When attached, keep flying and copy the new position back to World_Slot_1_Position.
Handler_MrMagneticBrella_AttachedFly 97F4 INC (IX+$11) Increase the animation timer.
97F7 LD A,(IX+$04) Fetch the alien's Y position.
97FA CP $70 Compare it with 70.
97FC LD A,(IX+$06) Fetch the vertical thrust.
97FF JR NC,Handler_MrMagneticBrella_ThrustUp Jump to Handler_MrMagneticBrella_ThrustUp if the alien is at or below mid-screen.
When above mid-screen, increase the downward thrust, up to a limit.
9801 AND A Jump to Handler_MrMagneticBrella_AttachedAddThrust if the thrust is negative.
9802 JP M,Handler_MrMagneticBrella_AttachedAddThrust
9805 CP $30 Jump to Handler_MrMagneticBrella_AttachedApplyThrust if the thrust is already at least 30.
9807 JR NC,Handler_MrMagneticBrella_AttachedApplyThrust
Handler_MrMagneticBrella_AttachedAddThrust 9809 ADD A,$02 Add 02 to the thrust.
Apply the thrust to the alien's Y position, stopping at the ground line.
Handler_MrMagneticBrella_AttachedApplyThrust 980B LD (IX+$06),A Write the thrust back.
980E SRA A Divide it by 10.
9810 SRA A
9812 SRA A
9814 SRA A
9816 ADD A,(IX+$04) Add it to the alien's Y position.
9819 CP $B0 Jump to Handler_MrMagneticBrella_AttachedWriteY if it is still above the ground line.
981B JR C,Handler_MrMagneticBrella_AttachedWriteY
AF is the ground line.
981D LD A,$AF A=AF.
Handler_MrMagneticBrella_AttachedWriteY 981F LD (IX+$04),A Write the Y position back.
Occasionally pick a new horizontal direction using RandomNumber.
9822 LD A,($5E40) Jump to Handler_MrMagneticBrella_DetachIfTerrain if RandomNumber is zero.
9825 LD C,A
9826 AND A
9827 JR Z,Handler_MrMagneticBrella_DetachIfTerrain
9829 AND %01111111 Keep only bits 0-6.
982B JR NZ,Handler_MrMagneticBrella_AccelerateFromFlag Jump to Handler_MrMagneticBrella_AccelerateFromFlag if the result is not zero.
982D LD A,C Fetch the stored random byte.
982E AND %10000000 Keep only bit 7.
9830 LD C,A Stash that sign bit.
9831 LD A,(IX+$08) Fetch the actor flags.
9834 AND %01111111 Keep only bits 0-6.
9836 OR C Merge in the sign bit and write the flags back.
9837 LD (IX+$08),A
Accelerate left or right from bit 7 of the flags.
Handler_MrMagneticBrella_AccelerateFromFlag 983A BIT 7,(IX+$08) Test bit 7 of the actor flags.
983E LD A,(IX+$05) Fetch the horizontal speed.
9841 JR NZ,Handler_MrMagneticBrella_CapSpeed Jump to Handler_MrMagneticBrella_CapSpeed if bit 7 is set.
When bit 7 is reset, speed up towards the right, up to a limit.
9843 AND A Jump to Handler_MrMagneticBrella_AddSpeed if the speed is negative.
9844 JP M,Handler_MrMagneticBrella_AddSpeed
9847 CP $30 Jump to Handler_MrMagneticBrella_WriteSpeedBack if the speed is already at least 30.
9849 JR NC,Handler_MrMagneticBrella_WriteSpeedBack
Handler_MrMagneticBrella_AddSpeed 984B ADD A,$02 Add 02 to the speed.
Handler_MrMagneticBrella_WriteSpeedBack 984D LD (IX+$05),A Write the speed back.
Stash the world X and rejoin the shared code at Handler_MrMagneticBrella_RestoreX.
Handler_MrMagneticBrella_StashWorldX 9850 LD H,(IX+$03) Fetch the high byte of the world X.
9853 LD L,(IX+$02) Fetch the low byte of the world X.
9856 PUSH HL Stash the world X on the stack.
9857 JP Handler_MrMagneticBrella_RestoreX Jump to Handler_MrMagneticBrella_RestoreX.
When below mid-screen, apply upward thrust.
Handler_MrMagneticBrella_ThrustUp 985A AND A Jump to Handler_MrMagneticBrella_SubtractThrust if the thrust is positive.
985B JP P,Handler_MrMagneticBrella_SubtractThrust
985E CP $D1 Jump to Handler_MrMagneticBrella_AttachedApplyThrust if the thrust is already below D1.
9860 JR C,Handler_MrMagneticBrella_AttachedApplyThrust
Handler_MrMagneticBrella_SubtractThrust 9862 SUB $02 Subtract 02 from the thrust.
9864 JR Handler_MrMagneticBrella_AttachedApplyThrust Jump to Handler_MrMagneticBrella_AttachedApplyThrust.
Handler_MrMagneticBrella_CapSpeed 9866 AND A Jump to Handler_MrMagneticBrella_SubtractSpeed if the speed is positive.
9867 JP P,Handler_MrMagneticBrella_SubtractSpeed
986A CP $D1 Jump to Handler_MrMagneticBrella_WriteSpeedBack if the speed is already below D1.
986C JR C,Handler_MrMagneticBrella_WriteSpeedBack
Handler_MrMagneticBrella_SubtractSpeed 986E SUB $02 Subtract 02 from the speed.
9870 JR Handler_MrMagneticBrella_WriteSpeedBack Jump to Handler_MrMagneticBrella_WriteSpeedBack.
When RandomNumber is zero, check for terrain under the alien. If there is some, detach the alien; otherwise carry on accelerating.
Handler_MrMagneticBrella_DetachIfTerrain 9872 CALL ReadTerrainCell Call ReadTerrainCell.
9875 LD A,D Jump to Handler_MrMagneticBrella_AccelerateFromFlag if the first terrain cell is empty.
9876 AND A
9877 JR Z,Handler_MrMagneticBrella_AccelerateFromFlag
9879 LD A,$80 Write 80 to World_Slot_1_Flags.
987B LD ($60B0),A
987E LD (IX+$08),$00 Write 00 to the actor flags.
9882 JR Handler_MrMagneticBrella_StashWorldX Jump to Handler_MrMagneticBrella_StashWorldX.
Prev: 9654 Up: Map Next: 9884