-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathAnimationEngine.a
More file actions
2532 lines (2289 loc) · 53 KB
/
Copy pathAnimationEngine.a
File metadata and controls
2532 lines (2289 loc) · 53 KB
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
;Animation types
AnimationType_Player1 = 0
AnimationType_Player1Bullet = 1
AnimationType_Player1Death = 2
AnimationType_Player2 = 3
AnimationType_Player2Bullet = 4
AnimationType_Player2Death = 5
AnimationType_Enemy1Bullet = 6
AnimationType_Enemy1Death = 14
AnimationType_Enemy1 = 22
!ifdef Scroller_LOTD {
AnimationType_Spell1 = 58
}
; 0 = Nothing
; 1 = Right
; 2 = Left
; 4 = Down
; 8 = Up
; Invalid inputs are treated as having nothing pressed, it doesn't make sense to have up+down+left for example.
AnimationDirectionToFrame !by 4,5,3,4,7,8,6,4,1,2,0,4,4,4,4,4
; Flags if the direction is a valid combination or not
AnimationDirectionIsValid !by 0,0,0,1,0,0,0,1,0,0,0,1,1,1,1,1
AnimationPlayer1BulletCount !by 0
AnimationPlayer2BulletCount !by 0
AnimationBulletCount !by 0
; The current enemy position pointer in the attack wave data
AnimationAttackWaveAddr !by 0,0
!zn
AnimationInit
ldx #Multiplex_items-1
.l1
lda #$ff
sta AnimationType,x
sta AnimationMovementMove,x
!ifdef Multiplex_SplitSort {
sta AnimationYPosToSort,x
}
sta AnimationYPos,x
lda #0
sta AnimationXPosHi,x
sta AnimationXPosLo,x
dex
bpl .l1
sta AnimationBulletCount
rts
!zn
AnimationKillEverythingExceptPlayers
ldx #Multiplex_items-1
.l1
lda AnimationType,x
!ifdef Scroller_Player1ShadowObject {
cmp #Scroller_Player1ShadowObject
beq .dontZap
}
cmp #AnimationType_Enemy1Bullet
bcc .dontZap
lda #$ff
sta AnimationType,x
!ifdef Multiplex_SplitSort {
sta AnimationYPosToSort,x
}
.dontZap
dex
bpl .l1
lda #0
sta AnimationBulletCount
rts
!zn
AnimationEnemyTriggerInit
lda #<AttackWaves
sta AnimationAttackWaveAddr
lda #>AttackWaves
sta AnimationAttackWaveAddr+1
rts
!zn
AnimationEnemyTriggerSkipMap
lda AnimationAttackWaveAddr
sta tempWork0
lda AnimationAttackWaveAddr+1
sta tempWork1
; This skips over enemies that are earlier in the scrolled level since we have jumped to the
; position and we don't want all enemies from earlier in the map to appear.
.l1
ldy #1
lda (tempWork0),y
cmp TotalScrollPosition+1
bcs .mightBe
.skipThis
lda tempWork0
clc
adc #7
sta tempWork0
bcc .l1
inc tempWork1
jmp .l1
.mightBe
; From the bcs above...
bne .definitelyGreaterThan
dey
; Check the lo byte
lda (tempWork0),y
cmp TotalScrollPosition
bcc .skipThis
.definitelyGreaterThan
lda tempWork0
sta AnimationAttackWaveAddr
lda tempWork1
sta AnimationAttackWaveAddr+1
rts
!zn
.noneFreeS jmp .noneFree
AnimationTriggerEnemies
lda AnimationAttackWaveAddr
sta tempWork0
lda AnimationAttackWaveAddr+1
sta tempWork1
; Continue to compare the TotalScrollPosition with the attack waves positions until the
; attack waves is equal to TotalScrollPosition.
.l1
ldy #1
lda TotalScrollPosition+1
cmp (tempWork0),y
beq .mightBe
; Attack wave hi is definitely different to the scroll position so we exit
.exitTrigger
; Update the 16 bit map position with how much we scroll this frame
lda TotalScrollPosition
clc
adc scrollerRealMovementYPixels
sta TotalScrollPosition
bcc .calcS1
inc TotalScrollPosition+1
.calcS1
; Store what we have so far
lda tempWork0
sta AnimationAttackWaveAddr
lda tempWork1
sta AnimationAttackWaveAddr+1
rts
.mightBe
dey
; Check the lo byte
lda TotalScrollPosition
cmp (tempWork0),y
bne .exitTrigger
; Exact position match so this enemy needs to be triggered
; Get the animation type to try to trigger
ldy #6
lda (tempWork0),y
clc
adc #AnimationType_Enemy1
tay
; Try to trigger it
jsr AnimationFindFreeSlot
bcs .noneFreeS
; Fill in the various information for the animation engine to take over
ldy #2
lda (tempWork0),y
sta AnimationMovementAddrLo,x
iny
lda (tempWork0),y
sta AnimationMovementAddrHi,x
; Now relocate from the SEUCK memory address to our address
.offset = AttackWaves - $340c
lda AnimationMovementAddrLo,x
clc
adc #<.offset
sta AnimationMovementAddrLo,x
lda AnimationMovementAddrHi,x
adc #>.offset
sta AnimationMovementAddrHi,x
!ifdef Scroller_WantAnimationMovementOrig {
lda AnimationMovementAddrLo,x
sta AnimationMovementOrigLo,x
lda AnimationMovementAddrHi,x
sta AnimationMovementOrigHi,x
}
iny
lda (tempWork0),y
asl
sta AnimationXPosLo,x
lda #0
rol
sta AnimationXPosHi,x
!ifdef Scroller_SpriteXAdjust {
lda LevelIsPushScrolled
bne .notLeft2
lda AnimationXPosLo,x
sec
sbc #1
sta AnimationXPosLo,x
bcs .notLeft2
dec AnimationXPosHi,x
.notLeft2
}
iny
lda (tempWork0),y
; Baphomet has no adjustment for the sprite Y position
!ifdef Scroller_NoSpriteYAdjust {} else {
; MPi: Note: There is a bug in SEUCK where a level switch from a static screen to a push scroll (that doesn't move) causes sprites to shift down one frame.
; MPi: Note: There is another bug in SEUCK where if a player repeatedly push scrolls and stops the sprites can be seen to slide over the background.
; Those two bugs are not implemented in this code, because they're horrible visual glitches.
ldy LevelIsPushScrolled
bne .noWrap
; Small adjustment to make it exactly match with SEUCK when scrolling or static screens
clc
adc scrollerRealMovementYPixels
bcc .noWrap ; Paranoia check :)
lda #$ff
.noWrap
}
sta AnimationYPos,x
; Calculate all the enemy information and store it for easier access
; Get the triggered enemy type
; Note: Use the enemy type without the AnimationType_Enemy1 adjustment
ldy #6
lda (tempWork0),y
tay
lda ObjectPropertiesTabLo,y
sta tempWork2
lda ObjectPropertiesTabHi,y
sta tempWork3
ldy #0
lda (tempWork2),y
and #15
beq .noSFX1
clc
adc #7
.noSFX1
sta AnimationFireSFX,x
lda (tempWork2),y
lsr
lsr
lsr
lsr
and #15
beq .noSFX2
clc
adc #7+8
.noSFX2
sta AnimationExplosionSFX,x
iny ; 1
lda (tempWork2),y
and #$f
sta AnimationFireDirectionType,x
lda (tempWork2),y
lsr
lsr
lsr
lsr
sta AnimationHealth,x
iny ; 2
lda (tempWork2),y
sta AnimationFireRateInit,x
sta AnimationFireRateCount,x
iny ; 3
lda (tempWork2),y
lsr
lsr
lsr
lsr
and #3
cmp #3
bne .notReally4a
; Speed 3 = 4 pixels in SEUCK
lda #4
.notReally4a
sta AnimationMoveSpeed,x
lda (tempWork2),y
lsr
lsr
lsr
lsr
lsr
lsr
sta AnimationFireSpeed,x
lda (tempWork2),y
and #15
sta AnimationCollisionLogic,x
iny ; 4
lda (tempWork2),y
lsr
lsr
lsr
lsr
and #7
clc
adc #AnimationType_Enemy1Bullet
sta AnimationFireType,x
lda (tempWork2),y
and #7
sta AnimationExplosionType,x
iny ; 5
iny ; 6
lda (tempWork2),y
sta AnimationPoints,x
.noneFree
; Get the next enemy and loop to test it
lda tempWork0
clc
adc #7
sta tempWork0
bcc .s1
inc tempWork1
.s1
jmp .l1
!zn
; Entry: Y = animation type
; Finds a free slot and X contains the index with carry clear. If no index is free then carry is set.
; Initialises the animation entries with type from Y if a slot could be found.
AnimationFindFreeSlot
ldx #0
.l1
lda AnimationType,x
bmi .l2
inx
cpx #Multiplex_items
bne .l1
sec
rts
.l2
jsr AnimationMutateToType
clc
rts
!zn
; Initialise the animation frames pointer and other internal stuff
; Input: X = Animation index
; Y = Animation type
AnimationMutateToType
tya
sta AnimationType,x
; Is it an enemy type?
cmp #AnimationType_Enemy1
bcc .notEnemy
; If yes, initialise the enemy specific data
lda #0
sta AnimationMovementFrameCount,x
sta AnimationMovementMove,x
.notEnemy
lda ObjectAnimationsTabLo,y
sta AnimationAnimsLo,x
sta tempWork3
lda ObjectAnimationsTabHi,y
sta AnimationAnimsHi,x
sta tempWork4
; Store the delay count
ldy #$12
lda (tempWork3),y
sta AnimationSpriteFrameCountDelayInit,x
; Store the colour
iny
; MPi: TODO: Initialise AnimationSpriteFrame,x with 0. Then in AnimationUpdateMultiplexor check to make sure AnimationSpriteFrame is never 0. If it is then break on inc d020 so it can be debugged
; Find out the animation type, see if it is consistently one particular type. Double check the animation allocation call for that animation type.
; When AnimationSpriteFrame,x equal to 0 (and the type matches) in AnimationUpdateFrameMovement at the beginning of the animation slot it can break before processing such an animation so it can be stepped through.
; lda #0
; sta AnimationSpriteFrame,x
lda (tempWork3),y
sta AnimationSpriteColour,x
; Extract the directional information
and #%00110000
sta Animation_DirectionalBits,x
beq .notDirectional
; Set the first blank frame for directional animations
; If the animation is sequential then this will get overwritten by the first animation update call
ldy #4
lda (tempWork3),y
and #$7f ; Paranoia
clc
adc #$40 ; Offset for where our sprites are actually stored in bank 3
sta AnimationSpriteFrame,x
; Init directional information
lda #0
sta AnimationDirectionIn,x
sta AnimationDirectionLastValidIn,x
.notDirectional
; Initialise the other frame data so it gets set on the first call in the update
lda #0
sta AnimationSpriteFrameCount,x
sta AnimationSpriteFrameCountDelay,x
rts
!zn
.semiRandomCount !by 0
; 33 long
.semiRandomDir1
!by 1,0,-1,0,-1,1,1,0,-1,-1,0,1,-1,1,-1,-1
!by 0,1,1,-1,0,1,-1,0,1,0,1,0,1,-1,0,1,-1
.semiRandomDir2
!by 2,0,-2,0,-2,2,2,0,-2,-2,0,2,-2,2,-2,-2
!by 0,2,2,-2,0,2,-2,0,2,0,2,0,2,-2,0,2,-2
.semiRandomDir3
!by 3,0,-3,0,-3,3,3,0,-3,-3,0,3,-3,3,-3,-3
!by 0,3,3,-3,0,3,-3,0,3,0,3,0,3,-3,0,3,-3
.ranSpeedTabL !by <.semiRandomDir1 , <.semiRandomDir2 , <.semiRandomDir3
.ranSpeedTabH !by >.semiRandomDir1 , >.semiRandomDir2 , >.semiRandomDir3
.setFireDirectionS jmp .setFireDirection
.setFireDirectionCrossS jmp .setFireDirectionCross
.setFireDirectionXS jmp .setFireDirectionX
AnimationUpdateEnemyFire
; Not allowed to early out because the fire rate count needs to be synced with the animation frame count for some enemy animations
ldx #Multiplex_items-1
.sp1
lda AnimationType,x
bpl .processTypeCont1
; Otherwise we loop around
.sl3
dex
bpl .sp1
rts
.processTypeCont1
!ifdef Scroller_LOTD {
cmp #AnimationType_Spell1
bcs .sl3
}
!ifdef Scroller_Player1ShadowObject {
cmp #Scroller_Player1ShadowObject
beq .sl3
}
cmp #AnimationType_Enemy1
bcc .sl3
; Blank direction means don't fire.
lda AnimationFireDirectionType,x
beq .sl3
sta .enemyFireDirectionType
; Process enemies wanting to fire
lda AnimationFireRateCount,x
dec AnimationFireRateCount,x
cmp #0 ; Compare needed on the previous value, not the dec result.
bne .sl3
lda AnimationFireRateInit,x
sta AnimationFireRateCount,x
; This dec tweak makes the SEUCK game 3 ghost enemy fire animations (see the unit test
; TESTGHST.P00) stay in sync with the ghost bullet.
; Without the dec the "bullet" gradually goes out of sync with the ghost animation.
; The one frame blank frame flicker for enemy 4 (object 25) is actually shown by the data
; running with the real SEUCK.
dec AnimationFireRateCount,x
; Try to fire but first check to see if we don't have too many bullets already active
lda AnimationBulletCount
cmp #10
bcs .sl3
; Backup the enemy fire speed and position ready for firing
lda AnimationFireSpeed,x
sta .enemyFireSpeed
lda #0
sec
sbc .enemyFireSpeed
sta .enemyFireSpeedNeg
lda AnimationXPosLo,x
sta .smxl+1
lda AnimationXPosHi,x
sta .smxh+1
lda AnimationYPos,x
sta .smy+1
!ifdef EnemyAimTest {
!ifndef EnemyAimTest_AllRandom {
lda AnimationType,x
sta .smAnimType+1
}
}
; lda AnimationDirectionLastValidIn,x
lda AnimationDirectionIn,x ; It looks like the enemy is not meant to remember the fire direction during animation hold frames when there is no movement
and #$f
bne .hadAMove
lda #8 ; No move so default to up
.hadAMove
sta .enemyLastValidMove
stx tempWork8
!ifdef Scroller_PlaySoundEffectsDuringGame {
lda AnimationFireSFX,x
beq .noSFX1
jsr SFXInit
.noSFX1
}
; Test for + and x fire
lda .enemyFireDirectionType
cmp #9
beq .setFireDirectionCrossS
cmp #10
beq .setFireDirectionXS
; Get the bullet type
ldy AnimationFireType,x
; Try to find a spare animation slot
jsr AnimationFindFreeSlot
bcs .sl2S2
inc AnimationBulletCount
; Found one spare!
; Update the velocity
!ifdef EnemyAimTest {
.smAnimType lda #0 ; Self modified and cached by code above
cmp #23 ; The correct enemy object ID
bne .notdoAimedFire
jmp .doAimedFire
;.notdoAimedFire
; For Star Skimmer
!if 0 {
cmp #21+01 ;Enemy object ID to use AIM
+lbeq .doAimedFire
cmp #21+02
+lbeq .doAimedFire
cmp #21+05
+lbeq .doAimedFire
cmp #21+08
+lbeq .doAimedFire
cmp #21+09
+lbeq .doAimedFire
cmp #21+10
+lbeq .doAimedFire
cmp #21+13
+lbeq .doAimedFire
cmp #21+18
+lbeq .doAimedFire
cmp #21+20
+lbeq .doAimedFire
cmp #21+33
+lbeq .doAimedFire
cmp #21+34
+lbeq .doAimedFire
cmp #21+35
+lbeq .doAimedFire
}
; Enable when using "EXPARMY1.P00"
!if 0 {
.notaim1
cmp #24 ;Enemy object ID to use AIM
bne .notaim2
jmp .doAimedFire
.notaim2
cmp #25 ;Enemy to use AIM
bne .notaim3
jmp .doAimedFire
.notaim3
cmp #26 ;Enemy to use AIM
bne .notaim4
jmp .doAimedFire
.notaim4
cmp #30 ;etc ...
bne .notaim5
jmp .doAimedFire
.notaim5
cmp #31
bne .notaim6
jmp .doAimedFire
.notaim6
cmp #33
bne .notaim7
jmp .doAimedFire
.notaim7
cmp #36
bne .notaim8
jmp .doAimedFire
.notaim8
cmp #37
bne .notaim9
jmp .doAimedFire
.notaim9
cmp #41
bne .notaim10
jmp .doAimedFire
.notaim10
cmp #43
bne .notaim11
jmp .doAimedFire
.notaim11
cmp #46
bne .notaim12
jmp .doAimedFire
.notaim12
cmp #47
bne .notaim13
jmp .doAimedFire
.notaim13
cmp #50
bne .notaim14
jmp .doAimedFire
.notaim14
cmp #51
bne .notaim15
jmp .doAimedFire
.notaim15
cmp #57
bne .notaim16
jmp .doAimedFire
.notaim16
}
}
lda .enemyFireDirectionType
cmp #9
bcs .over1
jmp .setFireDirection
.sl2S2 jmp .sl2
.over1
cmp #$b
beq .fireRandomly
lda #0
sta AnimationBulletSpeedX,x
sta AnimationBulletSpeedY,x
; Directional fire - Type $c
lda #1
bit .enemyLastValidMove
beq .notRight
lda .enemyFireSpeed
sta AnimationBulletSpeedX,x
.notRight
lda #2
bit .enemyLastValidMove
beq .notLeft
lda .enemyFireSpeedNeg
sta AnimationBulletSpeedX,x
.notLeft
lda #4
bit .enemyLastValidMove
beq .notDown
lda .enemyFireSpeed
sta AnimationBulletSpeedY,x
.notDown
lda #8
bit .enemyLastValidMove
beq .notUp
lda .enemyFireSpeedNeg
sta AnimationBulletSpeedY,x
.notUp
.setVelCacheFromBulletSpeedAndDoDirection
lda AnimationBulletSpeedX,x
sta .velCache
lda AnimationBulletSpeedY,x
sta .velCache+1
jmp .speedSetSoCalcDirection
.fireRandomly
lda .enemyFireSpeed
bne .someSpeed
.fireNoSpeed
sta AnimationBulletSpeedX,x
sta AnimationBulletSpeedY,x
sta AnimationDirectionIn,x
beq .noSpeedSoSkip
.someSpeed
; Convert the speed into a lookup table with self modifying code
tay
dey
lda .ranSpeedTabL,y
sta .smlu1+1
sta .smlu2+1
lda .ranSpeedTabH,y
sta .smlu1+2
sta .smlu2+2
; This implements random direction firing
inc .semiRandomCount
lda .semiRandomCount
and #31
sta .semiRandomCount
tay
.smlu1 lda .semiRandomDir1,y
sta AnimationBulletSpeedX,x
sta .velCache
iny
.smlu2 lda .semiRandomDir1,y
sta AnimationBulletSpeedY,x
sta .velCache+1
.speedSetSoCalcDirection
; Only do this code if the animation is directional
lda Animation_DirectionalBits,x
beq .noSpeedSoSkip
; Calculate the velocity to a directional in case the animation is directional
stx tempWork7
ldx .velCache
ldy .velCache+1
lda .enemyLastValidMove
jsr AnimationConvertXYToDirection
ldx tempWork7
sta AnimationDirectionIn,x
.noSpeedSoSkip
jsr .setBulletPosition
.sl2
ldx tempWork8
.sl1
dex
bmi .ret
jmp .sp1
.ret
rts
!ifdef EnemyAimTest {
.lastPlayerOffsetShotAt !by 0
.doAimedFire
; Player1Information or Player2Information is used depending on the active players
ldy #0
lda Player1Information+PlayerGameOffset_AnimationIndex
bmi .noPlayer1
lda Player2Information+PlayerGameOffset_AnimationIndex
bmi .noPlayer2
; Have both players, so...
lda .lastPlayerOffsetShotAt
bne .noPlayer2
.noPlayer1
ldy #Player2Information-Player1Information
bne .useThePlayerInY
.noPlayer2
ldy #0
; jmp .useThePlayerInY
.useThePlayerInY
sty .lastPlayerOffsetShotAt
; Using the enemy position for the player to bullet difference calculation
lda .smxh+1
lsr
lda .smxl+1
ror
lsr
sta .velCache
; Diff X
lda Player1Information + PlayerGameOffset_LastSafePosXHi,y
lsr
lda Player1Information + PlayerGameOffset_LastSafePosXLo,y
ror
lsr
sec
sbc .velCache
sta .velCache
bpl .storeIt1
eor #$FF ; Negate
sec
adc #0
.storeIt1
sta .enemyFireSpeedAbs
; Diff Y
lda .smy+1
lsr
lsr
sta .velCache+1
lda Player1Information + PlayerGameOffset_LastSafePosY,y
lsr
lsr
sec
sbc .velCache+1
sta .velCache+1
bpl .storeIt2
eor #$FF ; Negate
sec
adc #0
.storeIt2
ora .enemyFireSpeedAbs
sta .enemyFireSpeedAbs
; .velCache contains x and y deltas (both div 4)
; Shift down their values while .enemyFireSpeedAbs is faster than .enemyFireSpeed
.shiftIt
lda .enemyFireSpeedAbs
beq .useIt
cmp .enemyFireSpeed
bcc .useIt
beq .useIt
; ASR X and Y deltas until they fit the range we want
lda .velCache
asl
ror .velCache
lda .velCache+1
asl
ror .velCache+1
lsr .enemyFireSpeedAbs
jmp .shiftIt
.useIt
lda .velCache
bne .gotDirection
lda .velCache+1
bne .gotDirection
; No eventual direction so go back to random fire
jmp .fireRandomly
.gotDirection
lda .velCache
sta AnimationBulletSpeedX,x
lda .velCache+1
sta AnimationBulletSpeedY,x
; lda #0
; sta .enemyLastValidMove
jmp .speedSetSoCalcDirection
}
.setBulletPosition
; Update the bullet position with that from the enemy position
.smxl lda #0
sta AnimationXPosLo,x
.smxh lda #0
sta AnimationXPosHi,x
.smy lda #0
sta AnimationYPos,x
rts
.setFireDirection
cmp #1
bne .not1
lda #0
sta AnimationBulletSpeedX,x
lda .enemyFireSpeedNeg
sta AnimationBulletSpeedY,x
jmp .setVelCacheFromBulletSpeedAndDoDirection
.not1
cmp #2
bne .not2
lda .enemyFireSpeed
sta AnimationBulletSpeedX,x
lda .enemyFireSpeedNeg
sta AnimationBulletSpeedY,x
jmp .setVelCacheFromBulletSpeedAndDoDirection
.not2
cmp #3
bne .not3
lda .enemyFireSpeed
sta AnimationBulletSpeedX,x
lda #0
sta AnimationBulletSpeedY,x
jmp .setVelCacheFromBulletSpeedAndDoDirection
.not3
cmp #4
bne .not4
lda .enemyFireSpeed
sta AnimationBulletSpeedX,x
sta AnimationBulletSpeedY,x
jmp .setVelCacheFromBulletSpeedAndDoDirection
.not4
cmp #5
bne .not5
lda #0
sta AnimationBulletSpeedX,x
lda .enemyFireSpeed
sta AnimationBulletSpeedY,x
jmp .setVelCacheFromBulletSpeedAndDoDirection
.not5
cmp #6
bne .not6
lda .enemyFireSpeedNeg
sta AnimationBulletSpeedX,x
lda .enemyFireSpeed
sta AnimationBulletSpeedY,x
jmp .setVelCacheFromBulletSpeedAndDoDirection
.not6
cmp #7
bne .not7
lda .enemyFireSpeedNeg
sta AnimationBulletSpeedX,x
lda #0
sta AnimationBulletSpeedY,x
jmp .setVelCacheFromBulletSpeedAndDoDirection
.not7
; Last one must be 8
lda .enemyFireSpeedNeg
sta AnimationBulletSpeedX,x
sta AnimationBulletSpeedY,x
jmp .setVelCacheFromBulletSpeedAndDoDirection
.cachedEnemyFireType !by 0
.noMoreSpacesS
jmp .sl2
.setFireDirectionCross
; Get the bullet type
ldy AnimationFireType,x
sty .cachedEnemyFireType
; Try to find a spare animation slot
jsr AnimationFindFreeSlot
bcs .noMoreSpacesS
inc AnimationBulletCount
lda #0
sta AnimationBulletSpeedX,x
lda .enemyFireSpeed
sta AnimationBulletSpeedY,x
jsr .setBulletPosition
lda #%0100
sta AnimationDirectionIn,x
lda AnimationBulletCount
cmp #10
bcs .noMoreSpaces
ldy .cachedEnemyFireType
jsr AnimationFindFreeSlot
bcs .noMoreSpaces
inc AnimationBulletCount
lda #0
sta AnimationBulletSpeedX,x
lda .enemyFireSpeedNeg
sta AnimationBulletSpeedY,x
jsr .setBulletPosition
lda #%1000
sta AnimationDirectionIn,x
lda AnimationBulletCount
cmp #10
bcs .noMoreSpaces
ldy .cachedEnemyFireType
jsr AnimationFindFreeSlot
bcs .noMoreSpaces
inc AnimationBulletCount
lda .enemyFireSpeedNeg
sta AnimationBulletSpeedX,x
lda #0
sta AnimationBulletSpeedY,x
jsr .setBulletPosition
lda #%0010
sta AnimationDirectionIn,x
lda AnimationBulletCount
cmp #10
bcs .noMoreSpaces
ldy .cachedEnemyFireType
jsr AnimationFindFreeSlot
bcs .noMoreSpaces
inc AnimationBulletCount
lda .enemyFireSpeed
sta AnimationBulletSpeedX,x
lda #0
sta AnimationBulletSpeedY,x
jsr .setBulletPosition