Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/battle/battle_transitions.asm
1271 views
1
BattleTransition:
2
ld a, 1
3
ldh [hAutoBGTransferEnabled], a
4
call Delay3
5
xor a
6
ldh [hWY], a
7
dec a
8
ld [wUpdateSpritesEnabled], a
9
call DelayFrame
10
11
; Determine which OAM block is being used by the enemy trainer sprite (if there
12
; is one).
13
ld hl, wSpritePlayerStateData1ImageIndex
14
ldh a, [hSpriteIndex] ; enemy trainer sprite index (0 if wild battle)
15
ld c, a
16
ld b, 0
17
ld de, $10
18
.loop1
19
ld a, [hl]
20
cp $ff
21
jr z, .skip1
22
inc b
23
.skip1
24
add hl, de
25
dec c
26
jr nz, .loop1
27
28
; Clear OAM except for the blocks used by the player and enemy trainer sprites.
29
ld hl, wShadowOAMSprite04
30
ld c, 9
31
.loop2
32
ld a, b
33
swap a
34
cp l
35
jr z, .skip2 ; skip clearing the block if the enemy trainer is using it
36
push hl
37
push bc
38
ld bc, $10
39
xor a
40
call FillMemory
41
pop bc
42
pop hl
43
.skip2
44
ld de, $10
45
add hl, de
46
dec c
47
jr nz, .loop2
48
49
call Delay3
50
call LoadBattleTransitionTile
51
ld bc, 0
52
ld a, [wLinkState]
53
cp LINK_STATE_BATTLING
54
jr z, .linkBattle
55
call GetBattleTransitionID_WildOrTrainer
56
call GetBattleTransitionID_CompareLevels
57
call GetBattleTransitionID_IsDungeonMap
58
.linkBattle
59
ld hl, BattleTransitions
60
add hl, bc
61
add hl, bc
62
ld a, [hli]
63
ld h, [hl]
64
ld l, a
65
jp hl
66
67
const_def
68
const BIT_TRAINER_BATTLE_TRANSITION ; 0
69
const BIT_STRONGER_BATTLE_TRANSITION ; 1
70
const BIT_DUNGEON_BATTLE_TRANSITION ; 2
71
DEF NUM_BATTLE_TRANSITION_BITS EQU const_value
72
73
; the three GetBattleTransitionID functions set the first
74
; three bits of c, which determines what transition animation
75
; to play at the beginning of a battle
76
; bit 0: set if trainer battle
77
; bit 1: set if enemy is at least 3 levels higher than player
78
; bit 2: set if dungeon map
79
BattleTransitions:
80
table_width 2
81
dw BattleTransition_DoubleCircle ; %000
82
dw BattleTransition_Spiral ; %001
83
dw BattleTransition_Circle ; %010
84
dw BattleTransition_Spiral ; %011
85
dw BattleTransition_HorizontalStripes ; %100
86
dw BattleTransition_Shrink ; %101
87
dw BattleTransition_VerticalStripes ; %110
88
dw BattleTransition_Split ; %111
89
assert_table_length 1 << NUM_BATTLE_TRANSITION_BITS
90
91
GetBattleTransitionID_WildOrTrainer:
92
ld a, [wCurOpponent]
93
cp OPP_ID_OFFSET
94
jr nc, .trainer
95
res BIT_TRAINER_BATTLE_TRANSITION, c
96
ret
97
.trainer
98
set BIT_TRAINER_BATTLE_TRANSITION, c
99
ret
100
101
GetBattleTransitionID_CompareLevels:
102
ld hl, wPartyMon1HP
103
.faintedLoop
104
ld a, [hli]
105
or [hl]
106
jr nz, .notFainted
107
ld de, wPartyMon2 - (wPartyMon1 + 1)
108
add hl, de
109
jr .faintedLoop
110
.notFainted
111
ld de, wPartyMon1Level - (wPartyMon1HP + 1)
112
add hl, de
113
ld a, [hl]
114
add $3
115
ld e, a
116
ld a, [wCurEnemyLevel]
117
sub e
118
jr nc, .highLevelEnemy
119
res BIT_STRONGER_BATTLE_TRANSITION, c
120
ld a, 1
121
ld [wBattleTransitionSpiralDirection], a
122
ret
123
.highLevelEnemy
124
set BIT_STRONGER_BATTLE_TRANSITION, c
125
xor a
126
ld [wBattleTransitionSpiralDirection], a
127
ret
128
129
GetBattleTransitionID_IsDungeonMap:
130
ld a, [wCurMap]
131
ld e, a
132
ld hl, DungeonMaps1
133
.loop1
134
ld a, [hli]
135
cp $ff
136
jr z, .noMatch1
137
cp e
138
jr nz, .loop1
139
.match
140
set BIT_DUNGEON_BATTLE_TRANSITION, c
141
ret
142
.noMatch1
143
ld hl, DungeonMaps2
144
.loop2
145
ld a, [hli]
146
cp $ff
147
jr z, .noMatch2
148
ld d, a
149
ld a, [hli]
150
cp e
151
jr c, .loop2
152
ld a, e
153
cp d
154
jr nc, .match
155
.noMatch2
156
res BIT_DUNGEON_BATTLE_TRANSITION, c
157
ret
158
159
INCLUDE "data/maps/dungeon_maps.asm"
160
161
LoadBattleTransitionTile:
162
ld hl, vChars1 tile $7f
163
ld de, BattleTransitionTile
164
lb bc, BANK(BattleTransitionTile), 1
165
jp CopyVideoData
166
167
BattleTransitionTile: INCBIN "gfx/overworld/battle_transition.2bpp"
168
169
BattleTransition_BlackScreen:
170
ld a, $ff
171
ldh [rBGP], a
172
ldh [rOBP0], a
173
ldh [rOBP1], a
174
ret
175
176
; for non-dungeon trainer battles
177
; called regardless of mon levels, but does an
178
; outward spiral if enemy is at least 3 levels
179
; higher than player and does an inward spiral otherwise
180
BattleTransition_Spiral:
181
ld a, [wBattleTransitionSpiralDirection]
182
and a
183
jr z, .outwardSpiral
184
call BattleTransition_InwardSpiral
185
jr .done
186
.outwardSpiral
187
hlcoord 10, 10
188
ld a, $3
189
ld [wOutwardSpiralCurrentDirection], a
190
ld a, l
191
ld [wOutwardSpiralTileMapPointer + 1], a
192
ld a, h
193
ld [wOutwardSpiralTileMapPointer], a
194
ld b, 120
195
.loop
196
ld c, 3
197
.innerLoop
198
push bc
199
call BattleTransition_OutwardSpiral_
200
pop bc
201
dec c
202
jr nz, .innerLoop
203
call DelayFrame
204
dec b
205
jr nz, .loop
206
.done
207
call BattleTransition_BlackScreen
208
xor a
209
ld [wOutwardSpiralTileMapPointer + 1], a
210
ld [wOutwardSpiralTileMapPointer], a
211
ret
212
213
BattleTransition_InwardSpiral:
214
ld a, 7
215
ld [wInwardSpiralUpdateScreenCounter], a
216
hlcoord 0, 0
217
ld c, SCREEN_HEIGHT - 1
218
ld de, SCREEN_WIDTH
219
call BattleTransition_InwardSpiral_
220
inc c
221
jr .skip
222
.loop
223
ld de, SCREEN_WIDTH
224
call BattleTransition_InwardSpiral_
225
.skip
226
inc c
227
ld de, 1
228
call BattleTransition_InwardSpiral_
229
dec c
230
dec c
231
ld de, -SCREEN_WIDTH
232
call BattleTransition_InwardSpiral_
233
inc c
234
ld de, -1
235
call BattleTransition_InwardSpiral_
236
dec c
237
dec c
238
ld a, c
239
and a
240
jr nz, .loop
241
ret
242
243
BattleTransition_InwardSpiral_:
244
push bc
245
.loop
246
ld [hl], $ff
247
add hl, de
248
push bc
249
ld a, [wInwardSpiralUpdateScreenCounter]
250
dec a
251
jr nz, .skip
252
call BattleTransition_TransferDelay3
253
ld a, 7
254
.skip
255
ld [wInwardSpiralUpdateScreenCounter], a
256
pop bc
257
dec c
258
jr nz, .loop
259
pop bc
260
ret
261
262
BattleTransition_OutwardSpiral_:
263
ld bc, -SCREEN_WIDTH
264
ld de, SCREEN_WIDTH
265
ld a, [wOutwardSpiralTileMapPointer + 1]
266
ld l, a
267
ld a, [wOutwardSpiralTileMapPointer]
268
ld h, a
269
ld a, [wOutwardSpiralCurrentDirection]
270
cp $0
271
jr z, .up
272
cp $1
273
jr z, .left
274
cp $2
275
jr z, .down
276
cp $3
277
jr z, .right
278
.keepSameDirection
279
ld [hl], $ff
280
.done
281
ld a, l
282
ld [wOutwardSpiralTileMapPointer + 1], a
283
ld a, h
284
ld [wOutwardSpiralTileMapPointer], a
285
ret
286
.up
287
dec hl
288
ld a, [hl]
289
cp $ff
290
jr nz, .changeDirection
291
inc hl
292
add hl, bc
293
jr .keepSameDirection
294
.left
295
add hl, de
296
ld a, [hl]
297
cp $ff
298
jr nz, .changeDirection
299
add hl, bc
300
dec hl
301
jr .keepSameDirection
302
.down
303
inc hl
304
ld a, [hl]
305
cp $ff
306
jr nz, .changeDirection
307
dec hl
308
add hl, de
309
jr .keepSameDirection
310
.right
311
add hl, bc
312
ld a, [hl]
313
cp $ff
314
jr nz, .changeDirection
315
add hl, de
316
inc hl
317
jr .keepSameDirection
318
.changeDirection
319
ld [hl], $ff
320
ld a, [wOutwardSpiralCurrentDirection]
321
inc a
322
cp $4
323
jr nz, .skip
324
xor a
325
.skip
326
ld [wOutwardSpiralCurrentDirection], a
327
jr .done
328
329
FlashScreen:
330
BattleTransition_FlashScreen_:
331
ld hl, BattleTransition_FlashScreenPalettes
332
.loop
333
ld a, [hli]
334
cp 1
335
jr z, .done
336
ldh [rBGP], a
337
ld c, 2
338
call DelayFrames
339
jr .loop
340
.done
341
dec b
342
jr nz, BattleTransition_FlashScreen_
343
ret
344
345
BattleTransition_FlashScreenPalettes:
346
dc 3, 3, 2, 1
347
dc 3, 3, 3, 2
348
dc 3, 3, 3, 3
349
dc 3, 3, 3, 2
350
dc 3, 3, 2, 1
351
dc 3, 2, 1, 0
352
dc 2, 1, 0, 0
353
dc 1, 0, 0, 0
354
dc 0, 0, 0, 0
355
dc 1, 0, 0, 0
356
dc 2, 1, 0, 0
357
dc 3, 2, 1, 0
358
db 1 ; end
359
360
; used for low level trainer dungeon battles
361
BattleTransition_Shrink:
362
ld c, SCREEN_HEIGHT / 2
363
.loop
364
push bc
365
xor a
366
ldh [hAutoBGTransferEnabled], a
367
hlcoord 0, 7
368
decoord 0, 8
369
ld bc, -SCREEN_WIDTH * 2
370
call BattleTransition_CopyTiles1
371
hlcoord 0, 10
372
decoord 0, 9
373
ld bc, SCREEN_WIDTH * 2
374
call BattleTransition_CopyTiles1
375
hlcoord 8, 0
376
decoord 9, 0
377
ld bc, -2
378
call BattleTransition_CopyTiles2
379
hlcoord 11, 0
380
decoord 10, 0
381
ld bc, 2
382
call BattleTransition_CopyTiles2
383
ld a, $1
384
ldh [hAutoBGTransferEnabled], a
385
ld c, 6
386
call DelayFrames
387
pop bc
388
dec c
389
jr nz, .loop
390
call BattleTransition_BlackScreen
391
ld c, 10
392
jp DelayFrames
393
394
; used for high level trainer dungeon battles
395
BattleTransition_Split:
396
ld c, SCREEN_HEIGHT / 2
397
xor a
398
ldh [hAutoBGTransferEnabled], a
399
.loop
400
push bc
401
hlcoord 0, 16
402
decoord 0, 17
403
ld bc, -SCREEN_WIDTH * 2
404
call BattleTransition_CopyTiles1
405
hlcoord 0, 1
406
decoord 0, 0
407
ld bc, SCREEN_WIDTH * 2
408
call BattleTransition_CopyTiles1
409
hlcoord 18, 0
410
decoord 19, 0
411
ld bc, -2
412
call BattleTransition_CopyTiles2
413
hlcoord 1, 0
414
decoord 0, 0
415
ld bc, 2
416
call BattleTransition_CopyTiles2
417
call BattleTransition_TransferDelay3
418
call Delay3
419
pop bc
420
dec c
421
jr nz, .loop
422
call BattleTransition_BlackScreen
423
ld c, 10
424
jp DelayFrames
425
426
BattleTransition_CopyTiles1:
427
ld a, c
428
ld [wBattleTransitionCopyTilesOffset], a
429
ld a, b
430
ld [wBattleTransitionCopyTilesOffset + 1], a
431
ld c, 8
432
.loop1
433
push bc
434
push hl
435
push de
436
ld bc, SCREEN_WIDTH
437
call CopyData
438
pop hl
439
pop de
440
ld a, [wBattleTransitionCopyTilesOffset]
441
ld c, a
442
ld a, [wBattleTransitionCopyTilesOffset + 1]
443
ld b, a
444
add hl, bc
445
pop bc
446
dec c
447
jr nz, .loop1
448
ld l, e
449
ld h, d
450
ld a, $ff
451
ld c, SCREEN_WIDTH
452
.loop2
453
ld [hli], a
454
dec c
455
jr nz, .loop2
456
ret
457
458
BattleTransition_CopyTiles2:
459
ld a, c
460
ld [wBattleTransitionCopyTilesOffset], a
461
ld a, b
462
ld [wBattleTransitionCopyTilesOffset + 1], a
463
ld c, SCREEN_HEIGHT / 2
464
.loop1
465
push bc
466
push hl
467
push de
468
ld c, SCREEN_HEIGHT
469
.loop2
470
ld a, [hl]
471
ld [de], a
472
ld a, e
473
add SCREEN_WIDTH
474
jr nc, .noCarry1
475
inc d
476
.noCarry1
477
ld e, a
478
ld a, l
479
add SCREEN_WIDTH
480
jr nc, .noCarry2
481
inc h
482
.noCarry2
483
ld l, a
484
dec c
485
jr nz, .loop2
486
pop hl
487
pop de
488
ld a, [wBattleTransitionCopyTilesOffset]
489
ld c, a
490
ld a, [wBattleTransitionCopyTilesOffset + 1]
491
ld b, a
492
add hl, bc
493
pop bc
494
dec c
495
jr nz, .loop1
496
ld l, e
497
ld h, d
498
ld de, SCREEN_WIDTH
499
ld c, SCREEN_HEIGHT
500
.loop3
501
ld [hl], $ff
502
add hl, de
503
dec c
504
jr nz, .loop3
505
ret
506
507
; used for high level wild dungeon battles
508
BattleTransition_VerticalStripes:
509
ld c, SCREEN_HEIGHT
510
hlcoord 0, 0
511
decoord 1, 17
512
xor a
513
ldh [hAutoBGTransferEnabled], a
514
.loop
515
push bc
516
push hl
517
push de
518
push de
519
call BattleTransition_VerticalStripes_
520
pop hl
521
call BattleTransition_VerticalStripes_
522
call BattleTransition_TransferDelay3
523
pop hl
524
ld bc, -SCREEN_WIDTH
525
add hl, bc
526
ld e, l
527
ld d, h
528
pop hl
529
ld bc, SCREEN_WIDTH
530
add hl, bc
531
pop bc
532
dec c
533
jr nz, .loop
534
jp BattleTransition_BlackScreen
535
536
BattleTransition_VerticalStripes_:
537
ld c, SCREEN_WIDTH / 2
538
.loop
539
ld [hl], $ff
540
inc hl
541
inc hl
542
dec c
543
jr nz, .loop
544
ret
545
546
; used for low level wild dungeon battles
547
BattleTransition_HorizontalStripes:
548
ld c, SCREEN_WIDTH
549
hlcoord 0, 0
550
decoord 19, 1
551
xor a
552
ldh [hAutoBGTransferEnabled], a
553
.loop
554
push bc
555
push hl
556
push de
557
push de
558
call BattleTransition_HorizontalStripes_
559
pop hl
560
call BattleTransition_HorizontalStripes_
561
call BattleTransition_TransferDelay3
562
pop de
563
pop hl
564
pop bc
565
inc hl
566
dec de
567
dec c
568
jr nz, .loop
569
jp BattleTransition_BlackScreen
570
571
BattleTransition_HorizontalStripes_:
572
ld c, SCREEN_HEIGHT / 2
573
ld de, SCREEN_WIDTH * 2
574
.loop
575
ld [hl], $ff
576
add hl, de
577
dec c
578
jr nz, .loop
579
ret
580
581
; used for high level wild non-dungeon battles
582
; makes one full circle around the screen
583
; by animating each half circle one at a time
584
BattleTransition_Circle:
585
call BattleTransition_FlashScreen
586
lb bc, 0, SCREEN_WIDTH / 2
587
ld hl, BattleTransition_HalfCircle1
588
call BattleTransition_Circle_Sub1
589
ld c, SCREEN_WIDTH / 2
590
ld b, 1
591
ld hl, BattleTransition_HalfCircle2
592
call BattleTransition_Circle_Sub1
593
jp BattleTransition_BlackScreen
594
595
BattleTransition_FlashScreen:
596
ld b, $3
597
call BattleTransition_FlashScreen_
598
xor a
599
ldh [hAutoBGTransferEnabled], a
600
ret
601
602
BattleTransition_Circle_Sub1:
603
push bc
604
push hl
605
ld a, b
606
call BattleTransition_Circle_Sub2
607
pop hl
608
ld bc, 5
609
add hl, bc
610
call BattleTransition_TransferDelay3
611
pop bc
612
dec c
613
jr nz, BattleTransition_Circle_Sub1
614
ret
615
616
BattleTransition_TransferDelay3:
617
ld a, 1
618
ldh [hAutoBGTransferEnabled], a
619
call Delay3
620
xor a
621
ldh [hAutoBGTransferEnabled], a
622
ret
623
624
; used for low level wild non-dungeon battles
625
; makes two half circles around the screen
626
; by animating both half circles at the same time
627
BattleTransition_DoubleCircle:
628
call BattleTransition_FlashScreen
629
ld c, SCREEN_WIDTH / 2
630
ld hl, BattleTransition_HalfCircle1
631
ld de, BattleTransition_HalfCircle2
632
.loop
633
push bc
634
push hl
635
push de
636
push de
637
xor a
638
call BattleTransition_Circle_Sub2
639
pop hl
640
ld a, $1
641
call BattleTransition_Circle_Sub2
642
pop hl
643
ld bc, 5
644
add hl, bc
645
ld e, l
646
ld d, h
647
pop hl
648
add hl, bc
649
call BattleTransition_TransferDelay3
650
pop bc
651
dec c
652
jr nz, .loop
653
jp BattleTransition_BlackScreen
654
655
BattleTransition_Circle_Sub2:
656
ld [wBattleTransitionCircleScreenQuadrantY], a
657
ld a, [hli]
658
ld [wBattleTransitionCircleScreenQuadrantX], a
659
ld a, [hli]
660
ld e, a
661
ld a, [hli]
662
ld d, a
663
ld a, [hli]
664
ld h, [hl]
665
ld l, a
666
jp BattleTransition_Circle_Sub3
667
668
; halves
669
const_def
670
const CIRCLE_LEFT
671
const CIRCLE_RIGHT
672
673
MACRO half_circle
674
; quadrant x, circle data, target coord
675
db \1
676
dw \2
677
dwcoord \3, \4
678
ENDM
679
680
BattleTransition_HalfCircle1:
681
half_circle CIRCLE_RIGHT, BattleTransition_CircleData1, 18, 6
682
half_circle CIRCLE_RIGHT, BattleTransition_CircleData2, 19, 3
683
half_circle CIRCLE_RIGHT, BattleTransition_CircleData3, 18, 0
684
half_circle CIRCLE_RIGHT, BattleTransition_CircleData4, 14, 0
685
half_circle CIRCLE_RIGHT, BattleTransition_CircleData5, 10, 0
686
half_circle CIRCLE_LEFT, BattleTransition_CircleData5, 9, 0
687
half_circle CIRCLE_LEFT, BattleTransition_CircleData4, 5, 0
688
half_circle CIRCLE_LEFT, BattleTransition_CircleData3, 1, 0
689
half_circle CIRCLE_LEFT, BattleTransition_CircleData2, 0, 3
690
half_circle CIRCLE_LEFT, BattleTransition_CircleData1, 1, 6
691
692
BattleTransition_HalfCircle2:
693
half_circle CIRCLE_LEFT, BattleTransition_CircleData1, 1, 11
694
half_circle CIRCLE_LEFT, BattleTransition_CircleData2, 0, 14
695
half_circle CIRCLE_LEFT, BattleTransition_CircleData3, 1, 17
696
half_circle CIRCLE_LEFT, BattleTransition_CircleData4, 5, 17
697
half_circle CIRCLE_LEFT, BattleTransition_CircleData5, 9, 17
698
half_circle CIRCLE_RIGHT, BattleTransition_CircleData5, 10, 17
699
half_circle CIRCLE_RIGHT, BattleTransition_CircleData4, 14, 17
700
half_circle CIRCLE_RIGHT, BattleTransition_CircleData3, 18, 17
701
half_circle CIRCLE_RIGHT, BattleTransition_CircleData2, 19, 14
702
half_circle CIRCLE_RIGHT, BattleTransition_CircleData1, 18, 11
703
704
BattleTransition_Circle_Sub3:
705
push hl
706
ld a, [de]
707
ld c, a
708
inc de
709
.loop1
710
ld [hl], $ff
711
ld a, [wBattleTransitionCircleScreenQuadrantX]
712
and a
713
jr z, .skip1
714
inc hl
715
jr .skip2
716
.skip1
717
dec hl
718
.skip2
719
dec c
720
jr nz, .loop1
721
pop hl
722
ld a, [wBattleTransitionCircleScreenQuadrantY]
723
and a
724
ld bc, SCREEN_WIDTH
725
jr z, .skip3
726
ld bc, -SCREEN_WIDTH
727
.skip3
728
add hl, bc
729
ld a, [de]
730
inc de
731
cp -1
732
ret z
733
and a
734
jr z, BattleTransition_Circle_Sub3
735
ld c, a
736
.loop2
737
ld a, [wBattleTransitionCircleScreenQuadrantX]
738
and a
739
jr z, .skip4
740
dec hl
741
jr .skip5
742
.skip4
743
inc hl
744
.skip5
745
dec c
746
jr nz, .loop2
747
jr BattleTransition_Circle_Sub3
748
749
BattleTransition_CircleData1: db 2, 3, 5, 4, 9, -1
750
BattleTransition_CircleData2: db 1, 1, 2, 2, 4, 2, 4, 2, 3, -1
751
BattleTransition_CircleData3: db 2, 1, 3, 1, 4, 1, 4, 1, 4, 1, 3, 1, 2, 1, 1, 1, 1, -1
752
BattleTransition_CircleData4: db 4, 1, 4, 0, 3, 1, 3, 0, 2, 1, 2, 0, 1, -1
753
BattleTransition_CircleData5: db 4, 0, 3, 0, 3, 0, 2, 0, 2, 0, 1, 0, 1, 0, 1, -1
754
755