-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathanimations.asm
2661 lines (2488 loc) · 51.7 KB
/
animations.asm
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
; Draws a "frame block". Frame blocks are blocks of tiles that are put
; together to form frames in battle animations.
DrawFrameBlock:
ld l, c
ld h, b
ld a, [hli]
ld [wNumFBTiles], a
ld a, [wFBDestAddr + 1]
ld e, a
ld a, [wFBDestAddr]
ld d, a
xor a
ld [wFBTileCounter], a ; loop counter
.loop
ld a, [wFBTileCounter]
inc a
ld [wFBTileCounter], a
ld a, [wSubAnimTransform]
dec a
jr z, .flipHorizontalAndVertical ; SUBANIMTYPE_HVFLIP
dec a
jp z, .flipHorizontalTranslateDown ; SUBANIMTYPE_HFLIP
dec a
jr z, .flipBaseCoords ; SUBANIMTYPE_COORDFLIP
.noTransformation
ld a, [wBaseCoordY]
add [hl]
ld [de], a ; store Y
inc hl
inc de
ld a, [wBaseCoordX]
jr .finishCopying
.flipBaseCoords
ld a, [wBaseCoordY]
ld b, a
ld a, 136
sub b ; flip Y base coordinate
add [hl] ; Y offset
ld [de], a ; store Y
inc hl
inc de
ld a, [wBaseCoordX]
ld b, a
ld a, 168
sub b ; flip X base coordinate
.finishCopying ; finish copying values to OAM (when subanimation not transformed)
add [hl] ; X offset
ld [de], a ; store X
inc hl
inc de
ld a, [hli]
add $31 ; base tile ID for battle animations
ld [de], a ; store tile ID
inc de
ld a, [hli]
ld [de], a ; store flags
inc de
jp .nextTile
.flipHorizontalAndVertical
ld a, [wBaseCoordY]
add [hl] ; Y offset
ld b, a
ld a, 136
sub b ; flip Y coordinate
ld [de], a ; store Y
inc hl
inc de
ld a, [wBaseCoordX]
add [hl] ; X offset
ld b, a
ld a, 168
sub b ; flip X coordinate
ld [de], a ; store X
inc hl
inc de
ld a, [hli]
add $31 ; base tile ID for battle animations
ld [de], a ; store tile ID
inc de
; toggle horizontal and vertical flip
ld a, [hli] ; flags
and a
ld b, OAM_VFLIP | OAM_HFLIP
jr z, .storeFlags1
cp OAM_HFLIP
ld b, OAM_VFLIP
jr z, .storeFlags1
cp OAM_VFLIP
ld b, OAM_HFLIP
jr z, .storeFlags1
ld b, 0
.storeFlags1
ld a, b
ld [de], a
inc de
jp .nextTile
.flipHorizontalTranslateDown
ld a, [wBaseCoordY]
add [hl]
add 40 ; translate Y coordinate downwards
ld [de], a ; store Y
inc hl
inc de
ld a, [wBaseCoordX]
add [hl]
ld b, a
ld a, 168
sub b ; flip X coordinate
ld [de], a ; store X
inc hl
inc de
ld a, [hli]
add $31 ; base tile ID for battle animations
ld [de], a ; store tile ID
inc de
ld a, [hli]
bit OAM_X_FLIP, a
jr nz, .disableHorizontalFlip
.enableHorizontalFlip
set OAM_X_FLIP, a
jr .storeFlags2
.disableHorizontalFlip
res OAM_X_FLIP, a
.storeFlags2
ld [de], a
inc de
.nextTile
ld a, [wFBTileCounter]
ld c, a
ld a, [wNumFBTiles]
cp c
jp nz, .loop ; go back up if there are more tiles to draw
.afterDrawingTiles
ld a, [wFBMode]
cp FRAMEBLOCKMODE_02
jr z, .advanceFrameBlockDestAddr ; skip delay and don't clean OAM buffer
ld a, [wSubAnimFrameDelay]
ld c, a
call DelayFrames
ld a, [wFBMode]
cp FRAMEBLOCKMODE_03
jr z, .advanceFrameBlockDestAddr ; skip cleaning OAM buffer
cp FRAMEBLOCKMODE_04
jr z, .done ; skip cleaning OAM buffer and don't advance the frame block destination address
ld a, [wAnimationID]
cp GROWL
jr z, .resetFrameBlockDestAddr
call AnimationCleanOAM
.resetFrameBlockDestAddr
ld hl, wShadowOAM
ld a, l
ld [wFBDestAddr + 1], a
ld a, h
ld [wFBDestAddr], a ; set destination address to beginning of OAM buffer
ret
.advanceFrameBlockDestAddr
ld a, e
ld [wFBDestAddr + 1], a
ld a, d
ld [wFBDestAddr], a
.done
ret
PlayAnimation:
xor a
ldh [hROMBankTemp], a ; it looks like nothing reads this
ld [wSubAnimTransform], a
ld a, [wAnimationID] ; get animation number
dec a
ld l, a
ld h, 0
add hl, hl
ld de, AttackAnimationPointers ; animation command stream pointers
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
.animationLoop
vc_hook Stop_reducing_move_anim_flashing_Thunderbolt
ld a, [hli]
vc_hook_red Stop_reducing_move_anim_flashing_Reflect
vc_hook_blue Stop_reducing_move_anim_flashing_Self_Destruct
cp -1
vc_hook_blue Stop_reducing_move_anim_flashing_Reflect
jr z, .AnimationOver
cp FIRST_SE_ID ; is this subanimation or a special effect?
jr c, .playSubanimation
.doSpecialEffect
ld c, a
ld de, SpecialEffectPointers
.searchSpecialEffectTableLoop
ld a, [de]
cp c
jr z, .foundMatch
inc de
inc de
inc de
jr .searchSpecialEffectTableLoop
.foundMatch
ld a, [hli]
cp NO_MOVE - 1 ; is there a sound to play?
jr z, .skipPlayingSound
ld [wAnimSoundID], a ; store sound
push hl
push de
call GetMoveSound
call PlaySound
pop de
pop hl
.skipPlayingSound
push hl
inc de
ld a, [de]
ld l, a
inc de
ld a, [de]
ld h, a
ld de, .nextAnimationCommand
push de
jp hl ; jump to special effect function
.playSubanimation
ld c, a
and %00111111
ld [wSubAnimFrameDelay], a
xor a
sla c
rla
sla c
rla
ld [wWhichBattleAnimTileset], a
ld a, [hli] ; sound
ld [wAnimSoundID], a ; store sound
ld a, [hli] ; subanimation ID
ld c, l
ld b, h
ld l, a
ld h, 0
add hl, hl
ld de, SubanimationPointers
add hl, de
ld a, l
ld [wSubAnimAddrPtr], a
ld a, h
ld [wSubAnimAddrPtr + 1], a
ld l, c
ld h, b
push hl
ldh a, [rOBP0]
push af
ld a, [wAnimPalette]
ldh [rOBP0], a
call LoadMoveAnimationTiles
vc_hook Reduce_move_anim_flashing_Mega_Punch_Self_Destruct_Explosion
call LoadSubanimation
call PlaySubanimation
vc_hook_red Stop_reducing_move_anim_flashing_Mega_Punch
vc_hook_blue Stop_reducing_move_anim_flashing_Mega_Punch_Explosion
pop af
vc_hook_red Stop_reducing_move_anim_flashing_Blizzard
ldh [rOBP0], a
.nextAnimationCommand
vc_hook_red Stop_reducing_move_anim_flashing_Hyper_Beam
vc_hook_blue Stop_reducing_move_anim_flashing_Bubblebeam_Hyper_Beam_Blizzard
pop hl
vc_hook Stop_reducing_move_anim_flashing_Guillotine
jr .animationLoop
.AnimationOver
ret
LoadSubanimation:
vc_hook Reduce_move_anim_flashing_Guillotine
ld a, [wSubAnimAddrPtr + 1]
vc_hook Reduce_move_anim_flashing_Mega_Kick
ld h, a
vc_hook_red Reduce_move_anim_flashing_Blizzard
ld a, [wSubAnimAddrPtr]
vc_hook_red Reduce_move_anim_flashing_Self_Destruct
ld l, a
ld a, [hli]
ld e, a
vc_hook Reduce_move_anim_flashing_Explosion
ld a, [hl]
vc_hook Reduce_move_anim_flashing_Thunderbolt
ld d, a ; de = address of subanimation
ld a, [de]
vc_hook_blue Reduce_move_anim_flashing_Rock_Slide
ld b, a
vc_hook Reduce_move_anim_flashing_Spore
and %00011111
vc_hook Reduce_move_anim_flashing_Bubblebeam
ld [wSubAnimCounter], a ; number of frame blocks
vc_hook_red Reduce_move_anim_flashing_Rock_Slide
vc_hook_blue Reduce_move_anim_flashing_Self_Destruct
ld a, b
and %11100000
cp SUBANIMTYPE_ENEMY << 5
vc_hook_blue Reduce_move_anim_flashing_Blizzard
jr nz, .isNotType5
.isType5
call GetSubanimationTransform2
jr .saveTransformation
.isNotType5
vc_hook Reduce_move_anim_flashing_Hyper_Beam
call GetSubanimationTransform1
.saveTransformation
; place the upper 3 bits of a into bits 0-2 of a before storing
srl a
swap a
ld [wSubAnimTransform], a
cp SUBANIMTYPE_REVERSE
ld hl, 0
jr nz, .storeSubentryAddr
; if the animation is reversed, then place the initial subentry address at the end of the list of subentries
ld a, [wSubAnimCounter]
dec a
ld bc, 3
.loop
add hl, bc
dec a
jr nz, .loop
.storeSubentryAddr
inc de
add hl, de
ld a, l
ld [wSubAnimSubEntryAddr], a
ld a, h
ld [wSubAnimSubEntryAddr + 1], a
ret
; called if the subanimation type is not SUBANIMTYPE_ENEMY
; sets the transform to SUBANIMTYPE_NORMAL if it's the player's turn
; sets the transform to the subanimation type if it's the enemy's turn
GetSubanimationTransform1:
vc_hook Reduce_move_anim_flashing_Reflect
ld b, a
ldh a, [hWhoseTurn]
and a
ld a, b
ret nz
xor a ; SUBANIMTYPE_NORMAL << 5
ret
; called if the subanimation type is SUBANIMTYPE_ENEMY
; sets the transform to SUBANIMTYPE_HFLIP if it's the player's turn
; sets the transform to SUBANIMTYPE_NORMAL if it's the enemy's turn
GetSubanimationTransform2:
ldh a, [hWhoseTurn]
and a
ld a, SUBANIMTYPE_HFLIP << 5
ret z
xor a ; SUBANIMTYPE_NORMAL << 5
ret
; loads tile patterns for battle animations
LoadMoveAnimationTiles:
ld a, [wWhichBattleAnimTileset]
add a
add a
ld hl, MoveAnimationTilesPointers
ld e, a
ld d, 0
add hl, de
ld a, [hli]
ld [wTempTilesetNumTiles], a ; number of tiles
ld a, [hli]
ld e, a
ld a, [hl]
ld d, a ; de = address of tileset
ld hl, vSprites tile $31
ld b, BANK(MoveAnimationTiles0) ; ROM bank
ld a, [wTempTilesetNumTiles]
ld c, a ; number of tiles
jp CopyVideoData ; load tileset
MACRO anim_tileset
db \1
dw \2
db -1 ; padding
ENDM
MoveAnimationTilesPointers:
; number of tiles, gfx pointer
anim_tileset 79, MoveAnimationTiles0
anim_tileset 79, MoveAnimationTiles1
anim_tileset 64, MoveAnimationTiles2
MoveAnimationTiles0:
MoveAnimationTiles2:
INCBIN "gfx/battle/move_anim_0.2bpp"
MoveAnimationTiles1:
INCBIN "gfx/battle/move_anim_1.2bpp"
SlotMachineTiles2:
IF DEF(_RED)
INCBIN "gfx/slots/red_slots_2.2bpp"
ENDC
IF DEF(_BLUE)
INCBIN "gfx/slots/blue_slots_2.2bpp"
ENDC
SlotMachineTiles2End:
MoveAnimation:
push hl
push de
push bc
push af
call WaitForSoundToFinish
call SetAnimationPalette
ld a, [wAnimationID]
and a
jr z, .animationFinished
; if throwing a Poké Ball, skip the regular animation code
cp TOSS_ANIM
jr nz, .moveAnimation
ld de, .animationFinished
push de
jp TossBallAnimation
.moveAnimation
; check if battle animations are disabled in the options
ld a, [wOptions]
bit BIT_BATTLE_ANIMATION, a
jr nz, .animationsDisabled
call ShareMoveAnimations
call PlayAnimation
vc_hook_red Stop_reducing_move_anim_flashing_Bubblebeam_Mega_Kick
vc_hook_blue Stop_reducing_move_anim_flashing_Spore
jr .next4
.animationsDisabled
ld c, 30
call DelayFrames
.next4
vc_hook_red Stop_reducing_move_anim_flashing
vc_hook_blue Stop_reducing_move_anim_flashing_Rock_Slide_Dream_Eater
call PlayApplyingAttackAnimation ; shake the screen or flash the pic in and out (to show damage)
.animationFinished
call WaitForSoundToFinish
xor a
ld [wSubAnimSubEntryAddr], a
ld [wUnusedMoveAnimByte], a
ld [wSubAnimTransform], a
dec a ; NO_MOVE - 1
ld [wAnimSoundID], a
pop af
pop bc
pop de
pop hl
ret
ShareMoveAnimations:
; some moves just reuse animations from status conditions
ldh a, [hWhoseTurn]
and a
ret z
; opponent's turn
ld a, [wAnimationID]
cp AMNESIA
ld b, CONF_ANIM
jr z, .replaceAnim
cp REST
ld b, SLP_ANIM
ret nz
.replaceAnim
ld a, b
ld [wAnimationID], a
ret
PlayApplyingAttackAnimation:
; Generic animation that shows after the move's individual animation
; Different animation depending on whether the move has an additional effect and on whose turn it is
ld a, [wAnimationType]
and a
ret z
dec a
add a
ld c, a
ld b, 0
ld hl, AnimationTypePointerTable
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
AnimationTypePointerTable:
dw ShakeScreenVertically ; enemy mon has used a damaging move without a side effect
dw ShakeScreenHorizontallyHeavy ; enemy mon has used a damaging move with a side effect
dw ShakeScreenHorizontallySlow ; enemy mon has used a non-damaging move
dw BlinkEnemyMonSprite ; player mon has used a damaging move without a side effect
dw ShakeScreenHorizontallyLight ; player mon has used a damaging move with a side effect
dw ShakeScreenHorizontallySlow2 ; player mon has used a non-damaging move
ShakeScreenVertically:
call PlayApplyingAttackSound
ld b, 8
jp AnimationShakeScreenVertically
ShakeScreenHorizontallyHeavy:
call PlayApplyingAttackSound
ld b, 8
jp AnimationShakeScreenHorizontallyFast
ShakeScreenHorizontallySlow:
lb bc, 6, 2
jr AnimationShakeScreenHorizontallySlow
BlinkEnemyMonSprite:
call PlayApplyingAttackSound
jp AnimationBlinkEnemyMon
ShakeScreenHorizontallyLight:
call PlayApplyingAttackSound
ld b, 2
jp AnimationShakeScreenHorizontallyFast
ShakeScreenHorizontallySlow2:
lb bc, 3, 2
AnimationShakeScreenHorizontallySlow:
push bc
push bc
.loop1
ldh a, [rWX]
inc a
ldh [rWX], a
ld c, 2
call DelayFrames
dec b
jr nz, .loop1
pop bc
.loop2
ldh a, [rWX]
dec a
ldh [rWX], a
ld c, 2
call DelayFrames
dec b
jr nz, .loop2
pop bc
dec c
jr nz, AnimationShakeScreenHorizontallySlow
ret
SetAnimationPalette:
ld a, [wOnSGB]
and a
ld a, $e4
jr z, .notSGB
ld a, $f0
ld [wAnimPalette], a
ld b, $e4
ld a, [wAnimationID]
cp TRADE_BALL_DROP_ANIM
jr c, .next
cp TRADE_BALL_POOF_ANIM + 1
jr nc, .next
ld b, $f0
.next
ld a, b
ldh [rOBP0], a
ld a, $6c
ldh [rOBP1], a
ret
.notSGB
ld a, $e4
ld [wAnimPalette], a
vc_hook Reduce_move_anim_flashing_Dream_Eater
ldh [rOBP0], a
ld a, $6c
ldh [rOBP1], a
ret
PlaySubanimation:
ld a, [wAnimSoundID]
cp NO_MOVE - 1
jr z, .skipPlayingSound
call GetMoveSound
call PlaySound
.skipPlayingSound
ld hl, wShadowOAM
ld a, l
ld [wFBDestAddr + 1], a
ld a, h
ld [wFBDestAddr], a
ld a, [wSubAnimSubEntryAddr + 1]
ld h, a
ld a, [wSubAnimSubEntryAddr]
ld l, a
.loop
push hl
ld c, [hl] ; frame block ID
ld b, 0
ld hl, FrameBlockPointers
add hl, bc
add hl, bc
ld a, [hli]
ld c, a
ld a, [hli]
ld b, a
pop hl
inc hl
push hl
ld e, [hl] ; base coordinate ID
ld d, 0
ld hl, FrameBlockBaseCoords ; base coordinate table
add hl, de
add hl, de
ld a, [hli]
ld [wBaseCoordY], a
ld a, [hl]
ld [wBaseCoordX], a
pop hl
inc hl
ld a, [hl] ; frame block mode
ld [wFBMode], a
call DrawFrameBlock
call DoSpecialEffectByAnimationId ; run animation-specific function (if there is one)
ld a, [wSubAnimCounter]
dec a
ld [wSubAnimCounter], a
ret z
ld a, [wSubAnimSubEntryAddr + 1]
ld h, a
ld a, [wSubAnimSubEntryAddr]
ld l, a
ld a, [wSubAnimTransform]
cp SUBANIMTYPE_REVERSE
ld bc, 3
jr nz, .nextSubanimationSubentry
ld bc, -3
.nextSubanimationSubentry
add hl, bc
ld a, h
ld [wSubAnimSubEntryAddr + 1], a
ld a, l
ld [wSubAnimSubEntryAddr], a
jp .loop
AnimationCleanOAM:
push hl
push de
push bc
push af
call DelayFrame
call ClearSprites
pop af
pop bc
pop de
pop hl
ret
; this runs after each frame block is drawn in a subanimation
; it runs a particular special effect based on the animation ID
DoSpecialEffectByAnimationId:
push hl
push de
push bc
ld a, [wAnimationID]
ld hl, AnimationIdSpecialEffects
ld de, 3
call IsInArray
jr nc, .done
inc hl
ld a, [hli]
ld h, [hl]
ld l, a
ld de, .done
push de
jp hl
.done
pop bc
pop de
pop hl
ret
INCLUDE "data/battle_anims/special_effects.asm"
DoBallTossSpecialEffects:
ld a, [wCurItem]
cp ULTRA_BALL + 1 ; is it a Master Ball or Ultra Ball?
jr nc, .skipFlashingEffect
.flashingEffect ; do a flashing effect if it's Master Ball or Ultra Ball
ldh a, [rOBP0]
xor %00111100 ; complement colors 1 and 2
ldh [rOBP0], a
.skipFlashingEffect
ld a, [wSubAnimCounter]
cp 11 ; is it the beginning of the subanimation?
jr nz, .skipPlayingSound
; if it is the beginning of the subanimation, play a sound
ld a, SFX_BALL_TOSS
call PlaySound
.skipPlayingSound
ld a, [wIsInBattle]
cp 2 ; is it a trainer battle?
jr z, .isTrainerBattle
ld a, [wPokeBallAnimData]
cp $10 ; is the enemy pokemon the Ghost Marowak?
ret nz
; if the enemy pokemon is the Ghost Marowak, make it dodge during the last 3 frames
ld a, [wSubAnimCounter]
cp 3
jr z, .moveGhostMarowakLeft
cp 2
jr z, .moveGhostMarowakLeft
cp 1
ret nz
.moveGhostMarowakLeft
hlcoord 17, 0
ld de, 20
lb bc, 7, 7
.loop
push hl
push bc
call AnimCopyRowRight ; move row of tiles left
pop bc
pop hl
add hl, de
dec b
jr nz, .loop
ld a, %00001000
ldh [rNR10], a ; Channel 1 sweep register
ret
.isTrainerBattle ; if it's a trainer battle, shorten the animation by one frame
ld a, [wSubAnimCounter]
cp 3
ret nz
dec a
ld [wSubAnimCounter], a
ret
DoBallShakeSpecialEffects:
ld a, [wSubAnimCounter]
cp 4 ; is it the beginning of a shake?
jr nz, .skipPlayingSound
; if it is the beginning of a shake, play a sound and wait 2/3 of a second
ld a, SFX_TINK
call PlaySound
ld c, 40
call DelayFrames
.skipPlayingSound
ld a, [wSubAnimCounter]
dec a
ret nz
; if it's the end of the ball shaking subanimation, check if more shakes are left and restart the subanimation
ld a, [wNumShakes] ; number of shakes
dec a ; decrement number of shakes
ld [wNumShakes], a
ret z
; if there are shakes left, restart the subanimation
ld a, [wSubAnimSubEntryAddr]
ld l, a
ld a, [wSubAnimSubEntryAddr + 1]
ld h, a
ld de, -(4 * 3) ; 4 subentries and 3 bytes per subentry
add hl, de
ld a, l
ld [wSubAnimSubEntryAddr], a
ld a, h
ld [wSubAnimSubEntryAddr + 1], a
ld a, 5 ; number of subentries in the ball shaking subanimation plus one
ld [wSubAnimCounter], a
ret
; plays a sound after the second frame of the poof animation
DoPoofSpecialEffects:
ld a, [wSubAnimCounter]
cp 5
ret nz
ld a, SFX_BALL_POOF
jp PlaySound
DoRockSlideSpecialEffects:
ld a, [wSubAnimCounter]
cp 12
ret nc
cp 8
jr nc, .shakeScreen
cp 1
jp z, AnimationFlashScreen ; if it's the end of the subanimation, flash the screen
ret
; if the subanimation counter is between 8 and 11, shake the screen horizontally and vertically
.shakeScreen
ld b, 1
predef PredefShakeScreenHorizontally ; shake horizontally
ld b, 1
predef_jump PredefShakeScreenVertically ; shake vertically
FlashScreenEveryEightFrameBlocks:
ld a, [wSubAnimCounter]
and 7 ; is the subanimation counter exactly 8?
call z, AnimationFlashScreen ; if so, flash the screen
ret
; flashes the screen if the subanimation counter is divisible by 4
FlashScreenEveryFourFrameBlocks:
ld a, [wSubAnimCounter]
and 3
call z, AnimationFlashScreen
ret
; used for Explosion and Selfdestruct
DoExplodeSpecialEffects:
ld a, [wSubAnimCounter]
cp 1 ; is it the end of the subanimation?
jr nz, FlashScreenEveryFourFrameBlocks
; if it's the end of the subanimation, make the attacking pokemon disappear
hlcoord 1, 5
jp AnimationHideMonPic ; make pokemon disappear
; flashes the screen when subanimation counter is 1 modulo 4
DoBlizzardSpecialEffects:
ld a, [wSubAnimCounter]
cp 13
jp z, AnimationFlashScreen
cp 9
jp z, AnimationFlashScreen
cp 5
jp z, AnimationFlashScreen
cp 1
jp z, AnimationFlashScreen
ret
; flashes the screen at 3 points in the subanimation
; unused
FlashScreenUnused:
ld a, [wSubAnimCounter]
cp 14
jp z, AnimationFlashScreen
cp 9
jp z, AnimationFlashScreen
cp 2
jp z, AnimationFlashScreen
ret
; function to make the pokemon disappear at the beginning of the animation
TradeHidePokemon:
ld a, [wSubAnimCounter]
cp 6
ret nz
ld a, 2 * SCREEN_WIDTH + 7
jp ClearMonPicFromTileMap ; make pokemon disappear
; function to make a shaking pokeball jump up at the end of the animation
TradeShakePokeball:
ld a, [wSubAnimCounter]
cp 1
ret nz
; if it's the end of the animation, make the ball jump up
ld de, BallMoveDistances1
.loop
ld hl, wShadowOAM
ld bc, 4
.innerLoop
ld a, [de]
cp $ff
jr z, .done
add [hl] ; add to Y value of OAM entry
ld [hl], a
add hl, bc
ld a, l
cp 4 * 4 ; there are 4 entries, each 4 bytes
jr nz, .innerLoop
inc de
push bc
call Delay3
pop bc
jr .loop
.done
call AnimationCleanOAM
ld a, SFX_TRADE_MACHINE
jp PlaySound
BallMoveDistances1:
db -12, -12, -8
db -1 ; end
; function to make the pokeball jump up
TradeJumpPokeball:
ld de, BallMoveDistances2
.loop
ld hl, wShadowOAM
ld bc, 4
.innerLoop
ld a, [de]
cp $ff
jp z, ClearScreen
add [hl]
ld [hl], a
add hl, bc
ld a, l
cp 4 * 4 ; there are 4 entries, each 4 bytes
jr nz, .innerLoop
inc de
push de
ld a, [de]
cp 12
jr z, .playSound
cp $ff
jr nz, .skipPlayingSound
.playSound ; play sound if next move distance is 12 or this is the last one
ld a, SFX_SWAP
call PlaySound
.skipPlayingSound
push bc
ld c, 5
call DelayFrames
pop bc
ldh a, [hSCX] ; background scroll X
sub 8 ; scroll to the left
ldh [hSCX], a
pop de
jr .loop
BallMoveDistances2:
db 11, 12, -12, -7, 7, 12, -8, 8
db -1 ; end
; this function copies the current musical note graphic
; so that there are two musical notes flying towards the defending pokemon
DoGrowlSpecialEffects:
ld hl, wShadowOAM
ld de, wShadowOAMSprite04
ld bc, $10
call CopyData ; copy the musical note graphic
ld a, [wSubAnimCounter]
dec a
call z, AnimationCleanOAM ; clean up at the end of the subanimation
ret
; this is associated with Tail Whip, but Tail Whip doesn't use any subanimations
TailWhipAnimationUnused:
ld a, 1
ld [wSubAnimCounter], a
ld c, 20
jp DelayFrames
INCLUDE "data/battle_anims/special_effect_pointers.asm"
AnimationDelay10:
ld c, 10
jp DelayFrames
; calls a function with the turn flipped from player to enemy or vice versa
; input - hl - address of function to call
CallWithTurnFlipped:
ldh a, [hWhoseTurn]
push af
xor 1
ldh [hWhoseTurn], a
ld de, .returnAddress
push de
jp hl
.returnAddress
pop af
ldh [hWhoseTurn], a
ret
; flashes the screen for an extended period (48 frames)
AnimationFlashScreenLong:
ld a, 3 ; cycle through the palettes 3 times
ld [wFlashScreenLongCounter], a
ld a, [wOnSGB] ; running on SGB?
and a
ld hl, FlashScreenLongMonochrome
jr z, .loop
ld hl, FlashScreenLongSGB
.loop
push hl
.innerLoop
ld a, [hli]
cp 1
jr z, .endOfPalettes
ldh [rBGP], a
call FlashScreenLongDelay
jr .innerLoop
.endOfPalettes
ld a, [wFlashScreenLongCounter]
dec a
ld [wFlashScreenLongCounter], a
pop hl
jr nz, .loop
vc_hook_red Stop_reducing_move_anim_flashing_Psychic
ret
; BG palettes
FlashScreenLongMonochrome:
dc 3, 3, 2, 1
dc 3, 3, 3, 2
dc 3, 3, 3, 3
dc 3, 3, 3, 2
dc 3, 3, 2, 1
dc 3, 2, 1, 0