-
Notifications
You must be signed in to change notification settings - Fork 10
/
enemy.s
1181 lines (1086 loc) · 36.2 KB
/
enemy.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
HUMAN_ITEM_SPAWN_OFFSET = -15*8
ITEM_SPAWN_YSPEED = -3*8
MULTIEXPLOSION_DELAY = 2
SCRAP_DURATION = 40
FR_DEADRATAIR = 12
FR_DEADRATGROUND = 13
FR_DEADSPIDERAIR = 3
FR_DEADSPIDERGROUND = 4
FR_DEADFLY = 2
FR_DEADBATGROUND = 6
FR_DEADWALKERAIR = 12
FR_DEADWALKERGROUND = 13
TURRET_ANIMDELAY = 2
; Persistent NPC move logic. Branch off to script code according to game state
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8
MovePersistentNPC:
lda menuMode
bne MPNPC_InDialogue
ldy actT,x
ldx actScriptF-ACT_FIRSTPERSISTENTNPC,y
beq MPNPC_NoScript
lda scriptF
beq MPNPC_AnyScriptOK ;If continuous script is in same file, OK to exec
cmp actScriptF-ACT_FIRSTPERSISTENTNPC,y
bne MPNPC_NoScript ;Otherwise skip actor script when running
MPNPC_AnyScriptOK:
lda actScriptEP-ACT_FIRSTPERSISTENTNPC,y
jsr ExecScript
MPNPC_NoScript: ldx actIndex
MPNPC_InDialogue:
jmp MoveAndAttackHuman
; Common flying enemy movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveAccelerateFlyer:
lda #$00
MFE_CustomCharInfo:
sta temp6
ldy #AL_YMOVESPEED
lda (actLo),y
sta temp4 ;Vertical max. speed
lda actMoveCtrl,x
and #JOY_UP|JOY_DOWN
beq MFE_NoVertAccel
cmp #JOY_UP
beq MFE_AccelUp ;C=1 accelerate up (negative)
clc
MFE_AccelUp: iny
lda (actLo),y ;Vertical acceleration
ldy temp4
jsr AccActorYNegOrPos
MFE_NoVertAccel:ldy #AL_XMOVESPEED
lda (actLo),y
sta temp4 ;Horizontal max. speed
lda actMoveCtrl,x
and #JOY_LEFT|JOY_RIGHT
beq MFE_NoHorizAccel
and #JOY_LEFT
beq MFE_TurnRight
lda #$80
MFE_TurnRight: sta actD,x
asl ;Direction to carry
iny
lda (actLo),y ;Horizontal acceleration
ldy temp4
jsr AccActorXNegOrPos
MFE_NoHorizAccel:
ldy #AL_XCHECKOFFSET ;Horizontal obstacle check offset
lda (actLo),y
sta temp4
iny
lda (actLo),y ;Vertical obstacle check offset
ldy actSY,x ;Reverse if going up
bpl MFE_NoNegate
clc
eor #$ff
adc #$01
MFE_NoNegate: jsr MF_HasCharInfo
ldy actAIHelp,x ;Zero speed and reverse dir if requested
lda actMB,x
and #MB_HITWALL
beq MFE_NoHorizWall
lda #$00
sta actSX,x
tya
beq MFE_NoHorizTurn
lda #JOY_LEFT|JOY_RIGHT
jsr MFE_Reverse
MFE_NoHorizTurn:
MFE_NoHorizWall:lda actMB,x
and #MB_HITWALLVERTICAL
beq MFE_NoVertWall
lda #$00
sta actSY,x
tya
beq MFE_NoVertTurn
lda #JOY_UP|JOY_DOWN
MFE_Reverse: eor actMoveCtrl,x
sta actMoveCtrl,x
MFE_NoVertTurn:
MC_NoCollision:
MFE_NoVertWall: rts
; Floating droid update routine
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveDroid: lda #$02
tay
jsr LoopingAnimation
jsr MoveAccelerateFlyer
jmp AttackGeneric
; Floating mine update routine
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveFloatingMine:
lda #3
ldy #3
jsr LoopingAnimation
jsr MoveAccelerateFlyer
jmp MineCommon
; Rolling mine update routine
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveRollingMine:jsr MoveGeneric
lda actMB,x ;If not grounded and hitting wall,
cmp #MB_HITWALL ;climb up the wall
bne MRM_NoClimb
lda #10
ldy #4*8
jsr AccActorYNeg
MRM_NoClimb: inc actFd,x
lda actFd,x
and #$01
sta actF1,x
MineCommon: ldy #ACTI_PLAYER ;To avoid bugs, only ever collide with player
bmi MC_NoCollision
lda #DMG_ENEMYMINE
jsr CollideAndDamageTarget
bcc MC_NoCollision
jmp DestroyActorNoSource
; Flying craft update routine
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveFlyingCraft:lda actHp,x
beq MFC_Fall
jsr MoveAccelerateFlyer
lda actSX,x
clc
adc #2*8+4
bpl MFC_FrameOK1
lda #0
MFC_FrameOK1: lsr
lsr
lsr
cmp #5
bcc MFC_FrameOK2
lda #4
MFC_FrameOK2: sta actF1,x
cmp #2 ;Cannot fire when no speed (middle frame)
bne MFC_CanAttack
MFC_ContinueFall:
rts
MFC_Fall: jsr FallingMotionCommon
tay
beq MFC_ContinueFall
jmp ExplodeEnemy2_8 ;Drop item & explode at any collision
; Flying craft destroy routine
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
DestroyFlyingCraft:
stx temp6 ;Spawn one explosion when starts to fall
jsr GetAnyFreeActor
bcc DFC_NoRoom
jsr SpawnActor ;Actor type undefined at this point, will be initialized below
tya
tax
jsr ExplodeActor ;Play explosion sound & init animation
ldx temp6
DFC_NoRoom: rts
; Walking robot update routine
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveWalker: jsr MoveGeneric
MFC_CanAttack: jmp AttackGeneric
; Tank update routine
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveTank: jsr MoveGeneric ;Use human movement for physics
ldy #tankTurretOfs-turretFrameTbl
lda #1
jsr AnimateTurret
jsr AttackGeneric
jsr GetAbsXSpeed
clc
adc actFd,x
cmp #$30
bcc MT_NoWrap
sbc #$30
MT_NoWrap: sta actFd,x
lsr
lsr
lsr
lsr
sta actF1,x
ldy #AL_SIZEUP ;Modify size up based on turret direction
lda (actLo),y
ldy actF2,x
clc
adc tankSizeAddTbl,y
sta actSizeU,x
MFM_NoExplosion:rts
GetAbsXSpeed: lda actSX,x ;Tracks animation from absolute speed
bpl GAXS_Pos
Negate: clc
eor #$ff
adc #$01
GAXS_Pos: rts
; Ceiling turret update routine
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveTurret: lda actF2,x
ldy actFd,x ;Start from middle frame
bne MT_NoInit
inc actFd,x
lda #2
sta actF2,x
MT_NoInit: ldy #ceilingTurretOfs-turretFrameTbl
jsr AnimateTurret
lda actF2,x
sta actF1,x ;Ceiling turret uses only 1-part animation, so copy to frame1
jmp AttackGeneric
; Fire movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveFire: ldy #ACTI_FIRSTNPCBULLET
lda ULO_NoAirFlag+1 ;Destroy fires when noairflag on
bne MF_Destroy
lda actTime,x ;Restore oxygen level if not extinguished
beq MF_FullOxygen ;completely, destroy if depleted enough
cmp #EXTINGUISH_THRESHOLD
bcs MF_Destroy
dec actTime,x
bcc MF_Flash
MF_FullOxygen: sta actFlash,x ;Stop flickering at full oxygen
MF_Flash: lda #DMG_FIRE
jsr CollideAndDamagePlayer
lda #2
ldy #3
jsr LoopingAnimation
lda actF1,x
ora actFd,x
bne MF_NoSpawn
lda #ACTI_FIRSTEFFECT
ldy #ACTI_LASTNPCBULLET
jsr GetFreeActor
bcc MF_NoSpawn
lda #ACT_SMOKECLOUD
jsr SpawnActor
tya
tax
jsr InitActor ;Set collision size
lda #-15*8
jsr MoveActorY
lda #COLOR_FLICKER
sta actFlash,x
ldx actIndex
MSC_NoRemove:
MF_NoSpawn: rts
MF_Destroy: ldy actFall,x ;Damage source stored by the extinguisher bullet
jmp DestroyActor
; Smokecloud movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveSmokeCloud: lda upgrade
bmi MSC_NoSmokeDamage ;If filter installed, no damage
lda #DMG_SMOKE
jsr CollideAndDamagePlayer
MSC_NoSmokeDamage:
lda #-12
jsr MoveActorY
lda #4
ldy #3
jmp OneShotAnimateAndRemove
; Rat movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveRat: lda #FR_DEADRATGROUND
sta temp1
lda actHp,x
beq MR_Dead
jsr MoveGeneric
jmp AttackGeneric
MR_Dead: jsr DeadAnimalMotion
bcs MR_DeadGrounded
rts
MR_DeadGrounded:jsr MH_StopXSpeed
lda temp1
sta actF1,x
rts
; Fly movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveFly: lda actHp,x
beq MF_Dead
lda actMB,x
and #MB_HITWALL|MB_HITWALLVERTICAL
bne MF_SetNewControls
dec actTime,x
bpl MF_NoNewControls
MF_SetNewControls:
jsr Random
and #$03
tay
lda flyerDirTbl,y
sta actMoveCtrl,x
jsr Random
and #$1f
sta actTime,x
MF_NoNewControls:
jsr MoveAccelerateFlyer
inc actFd,x
lda actFd,x
and #$01
sta actF1,x
MF_Damage: lda actFd,x ;Common spider/fly/bat damage code
lsr
bcs MB_NoDamage ;Touch damage only each third frame
lda #DMG_SPIDER
jmp CollideAndDamagePlayer
MF_Dead: lda #2
ldy #FR_DEADFLY+1
jmp OneShotAnimateAndRemove
; Fish movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveFish: lda #CI_WATER
jsr MFE_CustomCharInfo
lda #2
ldy #1
MB_BatCommon: jsr LoopingAnimation
ldy #ACTI_PLAYER
jsr GetActorDistance
lda temp5 ;No damage after has moved past player
eor actD,x ;Otherwise use same damage code as spider
bpl MF_Damage
MB_NoDamage: rts
; Rock movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveRock: lda actTime,x ;Randomize X-speed on first frame
bne MR_HasRandomSpeed
jsr GetCharInfo
and #CI_OBSTACLE
bne MR_InitRemove ;Remove on init if inside wall (used to cache the first rock in caves)
inc actTime,x
jsr Random
and #$0f
sec
sbc #$08
sta actSX,x
MR_HasRandomSpeed:
ldy actF1,x ;Set size according to frame
lda rockSizeTbl,y
sta actSizeH,x
asl
sta actSizeU,x
lda rockDamageTbl,y
beq MR_NoDamage
jsr CollideAndDamagePlayer
MR_NoDamage: jsr BounceMotion
bcc MR_NoCollision
DestroyRock: lda #SFX_SHOTGUN
jsr PlaySfx
inc actF1,x
lda actF1,x
cmp #3
bcs RemoveRock
lda #-2*8
jsr MR_RandomizeSmallerRock
jsr GetFreeNPC
bcc MR_NoSpawn
lda #ACT_ROCK
jsr SpawnActor
lda actF1,x
sta actF1,y
stx temp6
tya
tax
jsr InitActor
lda #$00
jsr MR_RandomizeSmallerRock
ldx temp6
MR_NoCollision:
MR_NoSpawn: rts
RemoveRock: lda #-4*8
jsr MoveActorYNoInterpolation
lda #COLOR_FLICKER
sta actFlash,x
MR_InitRemove: lda #ACT_SMOKETRAIL
jmp TransformActor
MR_RandomizeSmallerRock:
sta temp1
jsr Random
and #$0f
clc
adc temp1
sta actSX,x
lda #-4*8
sta actSY,x
lda #$00 ;Reset ground flag
sta actMB,x
lda #HP_ROCK ;Reset hitpoints if was destroyed
sta actHp,x
rts
; Steam movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveSteam: lda #COLOR_FLICKER
sta actFlash,x
inc actTime,x
bmi MS_Invisible
lda #1
ldy #2
jsr LoopingAnimation
lda #DMG_STEAM
jmp CollideAndDamagePlayer
MS_Invisible: lda #3
sta actF1,x
rts
; Organic walker movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveOrganicWalker:
lda actHp,x
beq MOW_Dead
jsr MoveGeneric
jmp AttackGeneric
MOW_Dead: lda #FR_DEADWALKERGROUND
sta temp1
jmp MR_Dead
; Large walker movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveLargeWalker:jsr MoveGeneric
jsr GetAbsXSpeed
clc
adc actFd,x
sta actFd,x
rol
rol
rol
and #$03
sta actF1,x
and #$01
bne MLW_NoShake ;Shake screen when transitioning to 0 or 2 frame
ldy actFallL,x
beq MLW_NoShake
inc shakeScreen
MLW_NoShake: sta actFallL,x
jmp AttackGeneric
; Rock trap movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveRockTrap: lda actYH,x ;Trigger when player is below
cmp actYH+ACTI_PLAYER
bcs MRT_NoTrigger
lda actXH+ACTI_PLAYER
adc #$02 ;C=0 (next sbc will subtract one too much)
sbc actXH,x
cmp #$03 ;Trigger when X block distance is between -1 and +1
bcs MRT_NoTrigger
lda #ACT_ROCK
sta actT,x
jsr SetNotPersistent ;Disappear after triggering once
jmp InitActor
; High walker movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveHighWalker: jsr MoveGeneric
lda actSX,x
beq MHW_NoSpeed
inc actFd,x
MHW_NoSpeed: lda actFd,x
lsr
lsr
and #$03
sta actF1,x
lda #$ff
sta tgtActIndex
jsr AttackGeneric
ldy tgtActIndex ;Did attack?
bmi MHW_NoAttack
lda actT,y
cmp #ACT_LASER
bne MHW_NoLaser
lda actSX,y ;Use a special 22.5 degree angle frame
asl
lda #10
adc #$00
sta actF1,y
MHW_NoLaser: lda actSY,y ;Set 22.5 angle downward speed for bullet
bne MHW_SpeedYOK
lda actSX,y
bpl MHW_SpeedXPos
jsr Negate
MHW_SpeedXPos: lsr
sta actSY,y
MHW_SpeedYOK:
MRT_NoTrigger:
MHW_NoAttack: rts
; Turret animation routine
;
; Parameters: X actor index, A default frame, Y turret frame table start index
; Returns: Frame in actF2
; Modifies: A,Y,temp1-temp8,loader temp vars
AnimateTurret: sta AT_Default+1
AT_Loop: lda turretFrameTbl,y
beq AT_Default
cmp actCtrl,x
beq AT_Found
iny
iny
bne AT_Loop
AT_Found: lda turretFrameTbl+1,y
skip2
AT_Default: lda #$00
AT_FrameDone: cmp actF2,x
beq AT_NoAnim
ldy actAttackD,x
bne AT_NoAnim
bcc AT_AnimDown
AT_AnimUp: inc actF2,x
bne AT_AnimCommon
AT_AnimDown: dec actF2,x
AT_AnimCommon: lda #TURRET_ANIMDELAY
sta actAttackD,x
lda actTime,x
bpl AT_NoOngoingAttack
sec
sbc #TURRET_ANIMDELAY
sta actTime,x ;Restore time to the AI attack counter,
AT_NoOngoingAttack: ;since time was lost animating
AT_NoAnim: rts
; Fire destruction (transform into smoke)
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
DestroyFire: lda #ACT_SMOKECLOUD
jmp TransformActor
; Rat death
;
; Parameters: X actor index
; Returns: -
; Modifies: A
RatDeath: lda #FR_DEADRATAIR
RD_Common: pha
jsr AnimalDeathCommon
pla
RD_SetFrameAndSpeed:
sta actF1,x
lda #-28
sta actSY,x
jmp MH_ResetGrounded
; Spider death
;
; Parameters: X actor index
; Returns: -
; Modifies: A
SpiderDeath: lda #FR_DEADSPIDERAIR
bne RD_Common
; Fly / bat death
;
; Parameters: X actor index
; Returns: -
; Modifies: A
FlyDeath: lda #FR_DEADFLY
sta actF1,x
BatDeath:
AnimalDeathCommon:
jsr HD_Common
lda actSX,x ;Reduce the impulse from weapon
jsr Asr8
sta actSX,x
lda #SFX_ANIMALDEATH
jmp PlaySfx
; Organic walker death
;
; Parameters: X actor index
; Returns: -
; Modifies: A
OrganicWalkerDeath:
jsr HumanDeath
lda #FR_DEADWALKERAIR
bne RD_SetFrameAndSpeed
; Common dead animal falling motion
;
; Parameters: X actor index
; Returns: C Grounded status
; Modifies: A,Y,temp1-temp8,loader temp vars
DeadAnimalMotion:
jsr DeathFlickerAndRemove
jsr FallingMotionCommon
bpl DAM_NoWater
pha
lda #WATER_XBRAKING
jsr BrakeActorX
lda #WATER_YBRAKING*2
jsr BrakeActorY
pla
DAM_NoWater: and #MB_HITWALL
beq DAM_NoWallHit
jsr MH_StopXSpeed
DAM_NoWallHit: lda actMB,x
lsr
rts
; CPU destroy (activate object at explosion)
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
DestroyCPU: jsr ExplodeActor
ldy #MAX_LVLOBJ
DCPU_Search: dey
lda lvlObjX,y
cmp actXH,x
bne DCPU_Search
lda lvlObjY,y
and #$7f
cmp actYH,x
bne DCPU_Search
jmp ActivateObject ;Note: will loop endlessly or read out of bounds if not found
; Rising explosion generator
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveExplosionGeneratorRising:
lda #-4*8
jsr MoveActorY
; Explosion generator update routine
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveExplosionGenerator:
dec actFd,x
bpl MEG_NoNewExplosion
lda #MULTIEXPLOSION_DELAY
sta actFd,x
jsr GetAnyFreeActor
bcc MEG_NoRoom ;If no room, simply explode self
jsr SpawnActor ;Actor type undefined at this point, will be initialized below
lda actSX,x
sta temp1
lda actSY,x
sta temp2
tya
tax
jsr ExplodeActor ;Play explosion sound & init animation
lda temp1
jsr MEG_GetOffset
jsr MoveActorX
lda temp2
jsr MEG_GetOffset
jsr MoveActorY
ldx actIndex
dec actTime,x
bne MEG_NotLastExplosion
jmp RemoveActor
MEG_GetOffset: sta temp3
lsr
sta temp4
jsr Random
and temp3
sec
sbc temp4
MEG_NotLastExplosion:
MEG_NoNewExplosion:
rts
; Turn enemy into an explosion & drop item
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp vars
ExplodeEnemy_Ofs8:
jsr MoveActorCharUp
ExplodeEnemy: jsr DropItem
MEG_NoRoom: jmp ExplodeActor
; Generate 2 explosions at 8 pixel radius
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp vars
ExplodeEnemy2_8_Ofs6:
lda #6*8
skip2
ExplodeEnemy2_8_Ofs10:
lda #-10*8
jsr MoveActorYNoInterpolation
ExplodeEnemy2_8:lda #2
ldy #$3f
; Turn enemy into a multiple explosion generator & drop item
;
; Parameters: X actor index, A number of explosions, Y radius
; Returns: -
; Modifies: A,Y,temp vars
ExplodeEnemyMultiple:
sta actTime,x
tya
sta actSX,x
sta actSY,x
jsr DropItem
lda #ACT_EXPLOSIONGENERATOR
jmp TransformActor
; Generate 3 explosions at 8 pixel radius horizontally and 32 pixel radius
; vertically
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp vars
ExplodeEnemy3_Ofs24:
jsr MoveActorHalfBlockUp
lda #3
ldy #$ff
jsr EEM_SetCustomXRadius
jmp MoveActorCharUp
; Generate 2 explosions at 8 pixel radius horizontally and 15 pixel radius
; vertically
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp vars
ExplodeEnemy2_Ofs15:
jsr MoveActorHalfBlockUp
lda #2
ldy #$7f
EEM_SetCustomXRadius:
jsr ExplodeEnemyMultiple
lda #$3f
sta actSX,x
rts
; Generate 4 explosions at 32 pixel radius and spawn 3 pieces of scrap metal
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp vars
ExplodeEnemy4_Ofs15:
jsr MoveActorHalfBlockUp
lda #4
ldy #$ff
jsr ExplodeEnemyMultiple
EE_SpawnScrapMetal:
lda #-2*8-8
sta temp7 ;Initial base X-speed
jsr Random
sta temp8 ;Initial shape
EE_ScrapMetalLoop:
jsr GetAnyFreeActor
bcc EE_ScrapMetalDone
lda #ACT_SCRAPMETAL
jsr SpawnActor
jsr Random
and #$0f ;Randomize upward + sideways speed
clc
adc #-7*8
sta actSY,y
jsr Random
and #$0f
clc
adc temp7
sta actSX,y
inc temp8
lda temp8
and #$03
sta actF1,y
lda #SCRAP_DURATION
sta actTime,y
lda temp7
bpl EE_ScrapMetalDone
clc
adc #2*8
sta temp7
bne EE_ScrapMetalLoop
EE_ScrapMetalDone:
rts
; Generate 4 explosions at 15 pixel radius horizontally, rising vertically
; + also spawn metal pieces
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp vars
ExplodeEnemy4_Rising:
jsr ExplodeEnemy4_Ofs15
lda #8*8 ;Move back down to prevent explosions rising too high
jsr MoveActorY
lsr actSX,x
lsr actSY,x
lda #ACT_EXPLOSIONGENERATORRISING
jmp TransformActor
; Scrap metal movement
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp1-temp8,loader temp vars
MoveScrapMetal: jsr BounceMotion
; Flicker corpse, then remove
;
; Parameters: X actor index
; Returns: -
; Modifies: A,Y,temp regs
DeathFlickerAndRemove:
dec actTime,x
bmi DFAR_Remove
lda actTime,x ;Flicker and eventually remove the corpse
cmp #DEATH_FLICKER_DELAY
bcs DFAR_Done
lda #COLOR_FLICKER
sta actFlash,x
DFAR_Done: rts
DFAR_Remove: jmp RemoveActor
; Generator (screen shake) move routine
;
; Parameters: X actor number
; Returns: -
; Modifies: various
MoveGenerator: lda #PLOT_GENERATOR
jsr GetPlotBit
beq MG_NotOn
inc actFd,x
lda actFd,x
and #$01
sta shakeScreen
inc actTime,x
lda actTime,x
cmp #$03
bcc MG_NoSound
lda #SFX_GENERATOR
jsr PlaySfx
lda #$00
sta actTime,x
MG_NoSound:
MG_NotOn: rts
; Initiate humanoid enemy or player death
;
; Parameters: X actor index,temp8 damage source actor or $ff if none
; Returns: -
; Modifies: A,Y,temp1-temp8
HumanDeath: txa
bne HD_NotPlayer ;Reset dialogue / interaction menu modes
jsr StopScript ;if died during them
lda menuMode
cmp #MENU_DIALOGUE
bcc HD_NotInMenu
ldx #MENU_NONE
jsr SetMenuMode
HD_NotInMenu: ldx #ACTI_PLAYER
HD_NotPlayer: lda #SFX_HUMANDEATH
jsr PlaySfx
lda actF1,x
cmp #FR_SWIM
bcc HD_NotSwimming
jsr GetCharInfo1Below ;If space below, prefer to move
and #CI_OBSTACLE|CI_GROUND ;as the dying frames have hotspot at bottom
bne HD_SetFrame
lda #8*8
jsr MoveActorYNoInterpolation
jmp HD_SetFrame
HD_NotSwimming: lda #DEATH_YSPEED
sta actSY,x
jsr MH_ResetGrounded