Prev: AE78 Up: Map Next: B03B
AF1C: Handler: Sideways Missile
Fly a sideways missile (types A0 and A4). Flash the left or right warning marker, take laser hits off its hit count, step its X by its speed and steer its Y by its distance from the target. It explodes at Handler_Missile_FreezeWorld on reaching Jetman or the rover.
Input
IX Actor slot
Colour the missile banner and apply hits.
Handler_SidewaysMissile AF1C CALL TickThenExplode_CloseRange Call TickThenExplode_CloseRange.
AF1F JP C,Handler_Missile_InRange Jump to Handler_Missile_InRange if Jetman is in range.
Flash the banner tile on the side where the missile is.
AF22 CALL Handler_Missile Call Handler_Missile.
AF25 JR NC,Handler_Missile_FlashBanner Jump to Handler_Missile_FlashBanner if the missile is not to the left of Jetman.
The missile is to the left, so flash the first tile (587B) and set the second tile (587D) to a steady colour.
AF27 CALL FlashAttributeAlternative Call FlashAttributeAlternative to fetch the flashing attribute.
AF2A LD HL,$587B Point HL at the first banner tile (587B).
AF2D CALL Handler_Colour2x2 Call Handler_Colour2x2 to colour the tile with A.
AF30 LD HL,$587D Point HL at the second banner tile (587D).
AF33 JR Handler_Missile_BannerColour Jump to Handler_Missile_BannerColour to set the other tile to a steady colour.
The missile is not to the left, so flash the second tile (587D) and set the first tile (587B) to a steady colour.
Handler_Missile_FlashBanner AF35 CALL FlashAttributeAlternative Call FlashAttributeAlternative to fetch the flashing attribute.
AF38 LD HL,$587D Point HL at the second banner tile (587D).
AF3B CALL Handler_Colour2x2 Call Handler_Colour2x2 to colour the tile with A.
AF3E LD HL,$587B Point HL at the first banner tile (587B).
Set the other banner tile to INK:RED, PAPER:BLACK (BRIGHT).
Handler_Missile_BannerColour AF41 LD A,$42 Set the steady attribute in A to INK:RED, PAPER:BLACK (BRIGHT).
AF43 CALL Handler_Colour2x2 Call Handler_Colour2x2 to colour the tile with A.
Cycle the missile colour on even frames.
AF46 LD A,($5E42) Fetch GameTimer.
AF49 AND %00000001 Keep only bit 0.
AF4B JR NZ,Handler_Missile_TakeHit Jump to Handler_Missile_TakeHit if this is an odd frame.
AF4D LD A,(IX+$07) Fetch the actor colour.
AF50 CP $46 Jump to Handler_Missile_TakeHit if it is already INK:YELLOW, PAPER:BLACK (BRIGHT).
AF52 JR Z,Handler_Missile_TakeHit
AF54 LD A,($5E40) Fetch RandomNumber.
AF57 AND %00000111 Keep only bits 0-2.
AF59 JR NZ,Handler_Missile_WriteBright Jump to Handler_Missile_WriteBright if the result is not zero, else force 01.
AF5B INC A
Handler_Missile_WriteBright AF5C OR %01000000 Set bit 6.
AF5E LD (IX+$07),A Write it to the actor colour.
Skip to the movement unless the missile has been hit.
Handler_Missile_TakeHit AF61 BIT 0,(IX+$10) Jump to Handler_Missile_StepX if bit 0 of the explode flag is reset.
AF65 JR Z,Handler_Missile_StepX
Take one hit off the missile hit count.
AF67 DEC (IX+$16) Decrease *IX+16 by one.
Handler_Missile_Target AF6A JR Z,Handler_Missile_Destroyed Jump to Handler_Missile_Destroyed if the missile has been destroyed.
AF6C CALL SoundsLaserMissileHit Call SoundsLaserMissileHit.
Each missile hit adds 0100 points.
AF6F LD BC,$0100 Set the points to award in BC to 0100.
AF72 CALL AddPointsToScore Call AddPointsToScore.
AF75 LD (IX+$07),$42 Write INK:RED, PAPER:BLACK (BRIGHT) to the actor colour.
AF79 LD (IX+$10),$00 Write 00 to the explode flag.
Step the missile world X from its speed.
Handler_Missile_StepX AF7D LD L,(IX+$02) Fetch the actor world X.
AF80 LD H,(IX+$03) Fetch the high byte.
AF83 LD C,(IX+$05) Fetch the actor speed.
AF86 LD B,$00 Clear B.
AF88 LD A,C Copy the speed into A.
AF89 AND A Jump to Handler_Missile_WriteSteppedX if the speed is positive.
AF8A JP P,Handler_Missile_WriteSteppedX
AF8D DEC B Sign-extend into B.
Handler_Missile_WriteSteppedX AF8E ADD HL,BC Add the speed to the world X.
AF8F LD A,H Fetch the high byte.
AF90 AND %00011111 Keep only bits 0-4.
AF92 LD H,A Write it back.
AF93 LD (IX+$02),L Write the low byte.
AF96 LD (IX+$03),H Write the high byte.
Test the target range, then steer the Y from the distance.
AF99 CALL Handler_Missile_TestJetmanRange Call Handler_Missile_TestJetmanRange.
AF9C JR C,Handler_Missile_FreezeWorld Jump to Handler_Missile_FreezeWorld if the missile has reached its target.
Pick the Y steering band from the distance left, or just draw.
AF9E LD A,H Fetch the high byte of the distance left in HL.
AF9F CP $02 Jump to Handler_Missile_LowBand if it is less than 02.
AFA1 JR C,Handler_Missile_LowBand
AFA3 CP $10 Jump to Handler_Missile_MidBand if it is less than 10.
AFA5 JR C,Handler_Missile_MidBand
AFA7 CP $20 Jump to Handler_Missile_SteerY if it is less than 20.
AFA9 JR C,Handler_Missile_SteerY
Handler_Missile_Draw AFAB JP DrawCurrentActor_Draw Jump to DrawCurrentActor_Draw.
Kill Jetman if he is in range, then destroy the missile.
Handler_Missile_InRange AFAE CALL TickThenExplode_KillJetman Call TickThenExplode_KillJetman.
Handler_Missile_Destroyed AFB1 LD A,$01 Write 01 to Missile_Destroyed_Flag.
AFB3 LD ($6195),A
Destroying the missile adds 0500 points.
AFB6 LD BC,$0500 Set the points to award in BC to 0500.
AFB9 CALL AddPointsToScore Call AddPointsToScore.
AFBC LD DE,$BAA8 Point DE at the tune at Tune_Extra_1.
AFBF CALL QueueTune Call QueueTune.
AFC2 JP StartExplosion_SetSprite Jump to StartExplosion_SetSprite.
Steer the missile Y toward a band from the high byte.
Handler_Missile_SteerY AFC5 LD A,(IX+$04) Fetch the actor Y.
AFC8 CP $50 Compare it against 50.
Draw the missile once the Y matches its band, otherwise nudge it.
Handler_Missile_YReached AFCA JR Z,Handler_Missile_Draw Jump to Handler_Missile_Draw if they are equal.
AFCC JR NC,Handler_Missile_DecreaseY Jump to Handler_Missile_DecreaseY if the Y is already past the band.
AFCE INC A Increase the Y by two.
AFCF INC A
Handler_Missile_DecreaseY AFD0 DEC A Decrease the Y by one.
AFD1 LD (IX+$04),A Write it back.
AFD4 JR Handler_Missile_Draw Jump to Handler_Missile_Draw.
In the middle band, steer the Y toward 80.
Handler_Missile_MidBand AFD6 LD A,(IX+$04) Fetch the actor Y.
AFD9 CP $80 Compare it against 80.
AFDB JR Handler_Missile_YReached Jump to Handler_Missile_YReached.
In the low band, steer the Y toward A7.
Handler_Missile_LowBand AFDD LD A,(IX+$04) Fetch the actor Y.
AFE0 CP $A7 Compare it against A7.
AFE2 JR Z,Handler_Missile_Draw Jump to Handler_Missile_Draw if they are equal.
AFE4 INC A Increase the Y by one.
AFE5 CP $A7 Compare it against A7.
AFE7 JR Handler_Missile_YReached Jump to Handler_Missile_YReached.
The missile has reached Jetman or the rover: set PlayerInactive, then turn the world slots, the bomb and the aliens into craters and explosions.
Handler_Missile_FreezeWorld AFE9 LD A,$01 Write 01 to PlayerInactive.
AFEB LD ($5E6C),A
AFEE LD A,$C0 A=C0.
AFF0 LD ($60D8),A Write it to World_Slot_3.
AFF3 LD ($60A8),A Write it to World_Slot_1.
AFF6 LD ($60C0),A Write it to World_Slot_2.
Turn world slot 4 into an explosion if it is in use.
AFF9 LD A,($60F0) Fetch World_Slot_4.
AFFC AND A Jump to Handler_Missile_HideBomb if it is free.
AFFD JR Z,Handler_Missile_HideBomb
AFFF LD A,$5C Write 5C to World_Slot_4.
B001 LD ($60F0),A
Turn the bomb into a crater if it is in use.
Handler_Missile_HideBomb B004 LD A,($6198) Fetch Bomb_States.
B007 AND A Jump to Handler_Missile_ScanAliens if it is free.
B008 JR Z,Handler_Missile_ScanAliens
B00A LD A,$C0 Write C0 to Bomb_States.
B00C LD ($6198),A
Turn every active alien into an explosion.
Handler_Missile_ScanAliens B00F LD HL,$61B0 HL=Alien_Slot_1.
B012 LD DE,$0018 DE=0018.
B015 LD B,$06 Set an alien slot counter in B for 06 loops.
Handler_Missile_TestAlienSlot B017 LD A,(HL) Fetch the slot type.
B018 AND A Jump to Handler_Missile_NextAlienSlot if the slot is free.
B019 JR Z,Handler_Missile_NextAlienSlot
Work out from the slot type how to convert it.
B01B AND %11111110 Reset bit 0.
B01D CP $5A Jump to Handler_Missile_ConvertAlien if the type is 5A.
B01F JR Z,Handler_Missile_ConvertAlien
B021 CP $B6 Jump to Handler_Missile_ConvertAlien if the type is B6.
B023 JR Z,Handler_Missile_ConvertAlien
B025 AND %11111100 Keep only bits 2-7.
B027 CP $64 Jump to Handler_Missile_NextAlienSlot if the type is 64.
B029 JR Z,Handler_Missile_NextAlienSlot
B02B CP $C8 Jump to Handler_Missile_ConvertAlien if the type is C8.
B02D JR Z,Handler_Missile_ConvertAlien
B02F LD (HL),$5C Write 5C to the slot.
Move onto the next slot, looping until every alien is done.
Handler_Missile_NextAlienSlot B031 ADD HL,DE Move onto the next slot.
B032 DJNZ Handler_Missile_TestAlienSlot Decrease the slot counter by one and loop back to Handler_Missile_TestAlienSlot until every alien is processed.
B034 JP StartExplosion_SetSprite Jump to StartExplosion_SetSprite.
Handler_Missile_ConvertAlien B037 LD (HL),$64 Write 64 to the slot.
B039 JR Handler_Missile_NextAlienSlot Jump to Handler_Missile_NextAlienSlot.
Prev: AE78 Up: Map Next: B03B