Prev: 38326 Up: Map Next: 38670
38484: Handler: Drifting Alien
Count the alien, then drift it relative to the scroll in Jetman_Position.
Input
IX Actor slot
Handler_DriftingAlien 38484 LD HL,24158 HL=AlienCount.
38487 INC (HL) Increase AlienCount by one.
Compare the alien with Jetman_Position and pick a drift direction.
38488 LD H,(IX+3) Fetch the high byte of the world X.
38491 LD L,(IX+2) Fetch the low byte of the world X.
38494 LD DE,(24698) Fetch Jetman_Position.
38498 AND A Subtract the scroll position.
38499 SBC HL,DE
38501 BIT 4,H Jump to Handler_DriftingAlien_DriftRight if the alien is left of the scroll.
38503 JP NZ,Handler_DriftingAlien_DriftRight
Speed the alien up towards the left, up to a limit.
38506 LD C,0 Clear the reverse-animation flag.
38508 LD A,(IX+5) Jump to Handler_DriftingAlien_Decelerate if the horizontal speed is positive.
38511 AND A
38512 JP P,Handler_DriftingAlien_Decelerate
38515 CP 209 Jump to Handler_DriftingAlien_Loop if the speed is already below 209.
38517 JR C,Handler_DriftingAlien_Loop
Handler_DriftingAlien_Decelerate 38519 SUB 2 Subtract 2 from the speed.
Handler_DriftingAlien_Loop 38521 LD (IX+5),A Write the speed back.
Aim the vertical thrust at Jetman, or at mid-screen when Jetman is in the rover.
38524 LD A,(24696) Fetch the Jetman type from Jetman_Slot.
38527 CP 17 Jump to Handler_DriftingAlien_FetchJetmanY if Jetman is on foot.
38529 JR C,Handler_DriftingAlien_FetchJetmanY
38531 LD A,104 A=104.
38533 JR Handler_DriftingAlien_CompareY Jump to Handler_DriftingAlien_CompareY.
Handler_DriftingAlien_FetchJetmanY 38535 LD A,(24700) Fetch Jetman_Y.
Compare with the alien's Y position and, if the alien is above the target, increase the downward thrust, up to a limit.
Handler_DriftingAlien_CompareY 38538 SUB (IX+4) Subtract the alien's Y position.
38541 JP M,Handler_DriftingAlien_ThrustUp Jump to Handler_DriftingAlien_ThrustUp if the alien is below the target.
38544 LD A,(IX+6) Jump to Handler_DriftingAlien_AddThrust if the vertical thrust is negative.
38547 AND A
38548 JP M,Handler_DriftingAlien_AddThrust
38551 CP 48 Jump to Handler_DriftingAlien_ApplyThrust if the thrust is already at least 48.
38553 JR NC,Handler_DriftingAlien_ApplyThrust
Handler_DriftingAlien_AddThrust 38555 ADD A,2 Add 2 to the thrust.
Apply the thrust to the alien's Y position, bouncing at the top and bottom.
Handler_DriftingAlien_ApplyThrust 38557 LD (IX+6),A Write the thrust back.
38560 SRA A Divide it by 16.
38562 SRA A
38564 SRA A
38566 SRA A
38568 ADD A,(IX+4) Add it to the alien's Y position.
38571 CP 56 Jump to Handler_DriftingAlien_BounceTop if the alien is above the play area.
38573 JR C,Handler_DriftingAlien_BounceTop
38575 CP 176 Jump to Handler_DriftingAlien_BounceGround if the alien has hit the ground line.
38577 JR NC,Handler_DriftingAlien_BounceGround
38579 LD (IX+4),A Write the Y position back.
Animate the frame and colour, then continue at PlaceSpawnedAlien_Age.
Handler_DriftingAlien_Animate 38582 INC (IX+17) Increase the animation timer.
38585 LD A,(IX+17) Fetch the animation timer.
38588 AND %00000111 Keep only bits 0-2.
38590 BIT 7,C Jump to Handler_DriftingAlien_WriteFrame if the reverse-animation flag is set.
38592 JR NZ,Handler_DriftingAlien_WriteFrame
38594 XOR %00000111 Flip bits 0-2.
Sprite IDs begin at 72 ("The Blob: Frame 1").
Handler_DriftingAlien_WriteFrame 38596 ADD A,72 Add 72 for the drifting frames.
38598 LD (IX+0),A Write it to the actor type.
Alternate the colour using bit 0 of GameTimer.
38601 LD A,(24130) Fetch GameTimer.
38604 RLA Rotate it left once.
38605 AND %00000010 Keep only bit 1.
38607 ADD A,68 Add 68 for the colour.
38609 LD (IX+7),A Write it to the actor colour.
38612 JP PlaceSpawnedAlien_Age Jump to PlaceSpawnedAlien_Age.
When the alien is left of the scroll, drift right.
Handler_DriftingAlien_DriftRight 38615 LD C,128 Set the reverse-animation flag.
38617 LD A,(IX+5) Jump to Handler_DriftingAlien_AddSpeed if the horizontal speed is negative.
38620 AND A
38621 JP M,Handler_DriftingAlien_AddSpeed
38624 CP 48 Jump to Handler_DriftingAlien_Loop if the speed is already at least 48.
38626 JR NC,Handler_DriftingAlien_Loop
Handler_DriftingAlien_AddSpeed 38628 ADD A,2 Add 2 to the speed.
38630 JR Handler_DriftingAlien_Loop Jump to Handler_DriftingAlien_Loop.
When the alien is below the target, apply upward thrust.
Handler_DriftingAlien_ThrustUp 38632 LD A,(IX+6) Jump to Handler_DriftingAlien_SubtractThrust if the vertical thrust is positive.
38635 AND A
38636 JP P,Handler_DriftingAlien_SubtractThrust
38639 CP 209 Jump to Handler_DriftingAlien_ApplyThrust if the thrust is already below 209.
38641 JR C,Handler_DriftingAlien_ApplyThrust
Handler_DriftingAlien_SubtractThrust 38643 SUB 2 Subtract 2 from the thrust.
38645 JR Handler_DriftingAlien_ApplyThrust Jump to Handler_DriftingAlien_ApplyThrust.
Bounce off the top of the play area.
Handler_DriftingAlien_BounceTop 38647 LD A,(IX+6) Jump to Handler_DriftingAlien_Animate if the vertical thrust is positive.
38650 AND A
38651 JP P,Handler_DriftingAlien_Animate
Handler_DriftingAlien_NegateThrust 38654 NEG Negate the thrust.
38656 LD (IX+6),A Write it back.
38659 JR Handler_DriftingAlien_Animate Jump to Handler_DriftingAlien_Animate.
Bounce off the ground line.
Handler_DriftingAlien_BounceGround 38661 LD A,(IX+6) Jump to Handler_DriftingAlien_Animate if the vertical thrust is negative.
38664 AND A
38665 JP M,Handler_DriftingAlien_Animate
38668 JR Handler_DriftingAlien_NegateThrust Jump to Handler_DriftingAlien_NegateThrust.
Prev: 38326 Up: Map Next: 38670