Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/overworld/player_animations.asm
1271 views
1
EnterMapAnim::
2
call InitFacingDirectionList
3
ld a, $ec
4
ld [wSpritePlayerStateData1YPixels], a
5
call Delay3
6
push hl
7
call GBFadeInFromWhite
8
ld hl, wStatusFlags7
9
bit BIT_USED_FLY, [hl]
10
res BIT_USED_FLY, [hl]
11
jr nz, .flyAnimation
12
ld a, SFX_TELEPORT_ENTER_1
13
call PlaySound
14
ld hl, wStatusFlags6
15
bit BIT_DUNGEON_WARP, [hl]
16
res BIT_DUNGEON_WARP, [hl]
17
pop hl
18
jr nz, .dungeonWarpAnimation
19
call PlayerSpinWhileMovingDown
20
ld a, SFX_TELEPORT_ENTER_2
21
call PlaySound
22
call IsPlayerStandingOnWarpPadOrHole
23
ld a, b
24
and a
25
jr nz, .done
26
; if the player is not standing on a warp pad or hole
27
ld hl, wPlayerSpinInPlaceAnimFrameDelay
28
xor a
29
ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelay
30
inc a
31
ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayDelta
32
ld a, $8
33
ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayEndValue
34
ld [hl], $ff ; wPlayerSpinInPlaceAnimSoundID
35
ld hl, wFacingDirectionList
36
call PlayerSpinInPlace
37
.restoreDefaultMusic
38
call PlayDefaultMusic
39
.done
40
jp RestoreFacingDirectionAndYScreenPos
41
.dungeonWarpAnimation
42
ld c, 50
43
call DelayFrames
44
call PlayerSpinWhileMovingDown
45
jr .done
46
.flyAnimation
47
pop hl
48
ld de, BirdSprite
49
ld hl, vNPCSprites
50
lb bc, BANK(BirdSprite), $0c
51
call CopyVideoData
52
call LoadBirdSpriteGraphics
53
ld a, SFX_FLY
54
call PlaySound
55
ld hl, wFlyAnimUsingCoordList
56
xor a ; is using coord list
57
ld [hli], a ; wFlyAnimUsingCoordList
58
ld a, 12
59
ld [hli], a ; wFlyAnimCounter
60
ld [hl], $8 ; wFlyAnimBirdSpriteImageIndex (facing right)
61
ld de, FlyAnimationEnterScreenCoords
62
call DoFlyAnimation
63
call LoadPlayerSpriteGraphics
64
jr .restoreDefaultMusic
65
66
FlyAnimationEnterScreenCoords:
67
; y, x pairs
68
; This is the sequence of screen coordinates used by the overworld
69
; Fly animation when the player is entering a map.
70
db $05, $98
71
db $0F, $90
72
db $18, $88
73
db $20, $80
74
db $27, $78
75
db $2D, $70
76
db $32, $68
77
db $36, $60
78
db $39, $58
79
db $3B, $50
80
db $3C, $48
81
db $3C, $40
82
83
PlayerSpinWhileMovingDown:
84
ld hl, wPlayerSpinWhileMovingUpOrDownAnimDeltaY
85
ld a, $10
86
ld [hli], a ; wPlayerSpinWhileMovingUpOrDownAnimDeltaY
87
ld a, $3c
88
ld [hli], a ; wPlayerSpinWhileMovingUpOrDownAnimMaxY
89
call GetPlayerTeleportAnimFrameDelay
90
ld [hl], a ; wPlayerSpinWhileMovingUpOrDownAnimFrameDelay
91
jp PlayerSpinWhileMovingUpOrDown
92
93
_LeaveMapAnim::
94
call InitFacingDirectionList
95
call IsPlayerStandingOnWarpPadOrHole
96
ld a, b
97
and a
98
jr z, .playerNotStandingOnWarpPadOrHole
99
dec a
100
jp nz, LeaveMapThroughHoleAnim
101
.spinWhileMovingUp
102
ld a, SFX_TELEPORT_EXIT_1
103
call PlaySound
104
ld hl, wPlayerSpinWhileMovingUpOrDownAnimDeltaY
105
ld a, -$10
106
ld [hli], a ; wPlayerSpinWhileMovingUpOrDownAnimDeltaY
107
ld a, $ec
108
ld [hli], a ; wPlayerSpinWhileMovingUpOrDownAnimMaxY
109
call GetPlayerTeleportAnimFrameDelay
110
ld [hl], a ; wPlayerSpinWhileMovingUpOrDownAnimFrameDelay
111
call PlayerSpinWhileMovingUpOrDown
112
call IsPlayerStandingOnWarpPadOrHole
113
ld a, b
114
dec a
115
jr z, .playerStandingOnWarpPad
116
; if not standing on a warp pad, there is an extra delay
117
ld c, 10
118
call DelayFrames
119
.playerStandingOnWarpPad
120
call GBFadeOutToWhite
121
jp RestoreFacingDirectionAndYScreenPos
122
.playerNotStandingOnWarpPadOrHole
123
ld a, $4
124
call StopMusic
125
ld a, [wStatusFlags6]
126
bit BIT_ESCAPE_WARP, a
127
jr z, .flyAnimation
128
; if going to the last used pokemon center
129
ld hl, wPlayerSpinInPlaceAnimFrameDelay
130
ld a, 16
131
ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelay
132
ld a, -1
133
ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayDelta
134
xor a
135
ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayEndValue
136
ld [hl], SFX_TELEPORT_EXIT_2 ; wPlayerSpinInPlaceAnimSoundID
137
ld hl, wFacingDirectionList
138
call PlayerSpinInPlace
139
jr .spinWhileMovingUp
140
.flyAnimation
141
call LoadBirdSpriteGraphics
142
ld hl, wFlyAnimUsingCoordList
143
ld a, $ff ; is not using coord list (flap in place)
144
ld [hli], a ; wFlyAnimUsingCoordList
145
ld a, 8
146
ld [hli], a ; wFlyAnimCounter
147
ld [hl], $c ; wFlyAnimBirdSpriteImageIndex
148
call DoFlyAnimation
149
ld a, SFX_FLY
150
call PlaySound
151
ld hl, wFlyAnimUsingCoordList
152
xor a ; is using coord list
153
ld [hli], a ; wFlyAnimUsingCoordList
154
ld a, $c
155
ld [hli], a ; wFlyAnimCounter
156
ld [hl], $c ; wFlyAnimBirdSpriteImageIndex (facing right)
157
ld de, FlyAnimationScreenCoords1
158
call DoFlyAnimation
159
ld c, 40
160
call DelayFrames
161
ld hl, wFlyAnimCounter
162
ld a, 11
163
ld [hli], a ; wFlyAnimCounter
164
ld [hl], $8 ; wFlyAnimBirdSpriteImageIndex (facing left)
165
ld de, FlyAnimationScreenCoords2
166
call DoFlyAnimation
167
call GBFadeOutToWhite
168
jp RestoreFacingDirectionAndYScreenPos
169
170
FlyAnimationScreenCoords1:
171
; y, x pairs
172
; This is the sequence of screen coordinates used by the first part
173
; of the Fly overworld animation.
174
db $3C, $48
175
db $3C, $50
176
db $3B, $58
177
db $3A, $60
178
db $39, $68
179
db $37, $70
180
db $37, $78
181
db $33, $80
182
db $30, $88
183
db $2D, $90
184
db $2A, $98
185
db $27, $A0
186
187
FlyAnimationScreenCoords2:
188
; y, x pairs
189
; This is the sequence of screen coordinates used by the second part
190
; of the Fly overworld animation.
191
db $1A, $90
192
db $19, $80
193
db $17, $70
194
db $15, $60
195
db $12, $50
196
db $0F, $40
197
db $0C, $30
198
db $09, $20
199
db $05, $10
200
db $00, $00
201
202
db $F0, $00
203
204
LeaveMapThroughHoleAnim:
205
ld a, $ff
206
ld [wUpdateSpritesEnabled], a ; disable UpdateSprites
207
; shift upper half of player's sprite down 8 pixels and hide lower half
208
ld a, [wShadowOAMSprite00TileID]
209
ld [wShadowOAMSprite02TileID], a
210
ld a, [wShadowOAMSprite01TileID]
211
ld [wShadowOAMSprite03TileID], a
212
ld a, $a0
213
ld [wShadowOAMSprite00YCoord], a
214
ld [wShadowOAMSprite01YCoord], a
215
ld c, 2
216
call DelayFrames
217
; hide upper half of player's sprite
218
ld a, $a0
219
ld [wShadowOAMSprite02YCoord], a
220
ld [wShadowOAMSprite03YCoord], a
221
call GBFadeOutToWhite
222
ld a, $1
223
ld [wUpdateSpritesEnabled], a ; enable UpdateSprites
224
jp RestoreFacingDirectionAndYScreenPos
225
226
DoFlyAnimation:
227
ld a, [wFlyAnimBirdSpriteImageIndex]
228
xor $1 ; make the bird flap its wings
229
ld [wFlyAnimBirdSpriteImageIndex], a
230
ld [wSpritePlayerStateData1ImageIndex], a
231
call Delay3
232
ld a, [wFlyAnimUsingCoordList]
233
cp $ff
234
jr z, .skipCopyingCoords ; if the bird is flapping its wings in place
235
ld hl, wSpritePlayerStateData1YPixels
236
ld a, [de]
237
inc de
238
ld [hli], a ; y
239
inc hl
240
ld a, [de]
241
inc de
242
ld [hl], a ; x
243
.skipCopyingCoords
244
ld a, [wFlyAnimCounter]
245
dec a
246
ld [wFlyAnimCounter], a
247
jr nz, DoFlyAnimation
248
ret
249
250
LoadBirdSpriteGraphics:
251
ld de, BirdSprite
252
ld hl, vNPCSprites
253
lb bc, BANK(BirdSprite), 12
254
call CopyVideoData
255
ld de, BirdSprite tile 12 ; moving animation sprite
256
ld hl, vNPCSprites2
257
lb bc, BANK(BirdSprite), 12
258
jp CopyVideoData
259
260
InitFacingDirectionList:
261
ld a, [wSpritePlayerStateData1ImageIndex] ; (image index is locked to standing images)
262
ld [wSavedPlayerFacingDirection], a
263
ld a, [wSpritePlayerStateData1YPixels]
264
ld [wSavedPlayerScreenY], a
265
ld hl, PlayerSpinningFacingOrder
266
ld de, wFacingDirectionList
267
ld bc, 4
268
call CopyData
269
ld a, [wSpritePlayerStateData1ImageIndex] ; (image index is locked to standing images)
270
ld hl, wFacingDirectionList
271
; find the place in the list that matches the current facing direction
272
.loop
273
cp [hl]
274
inc hl
275
jr nz, .loop
276
dec hl
277
ret
278
279
PlayerSpinningFacingOrder:
280
; The order of the direction the player's sprite is facing when teleporting
281
; away. Creates a spinning effect.
282
db SPRITE_FACING_DOWN, SPRITE_FACING_LEFT, SPRITE_FACING_UP, SPRITE_FACING_RIGHT
283
284
SpinPlayerSprite:
285
; copy the current value from the list into the sprite data and rotate the list
286
ld a, [hl]
287
ld [wSpritePlayerStateData1ImageIndex], a ; (image index is locked to standing images)
288
push hl
289
ld hl, wFacingDirectionList
290
ld de, wFacingDirectionList - 1
291
ld bc, 4
292
call CopyData
293
ld a, [wFacingDirectionList - 1]
294
ld [wFacingDirectionList + 3], a
295
pop hl
296
ret
297
298
PlayerSpinInPlace:
299
call SpinPlayerSprite
300
ld a, [wPlayerSpinInPlaceAnimFrameDelay]
301
ld c, a
302
and $3
303
jr nz, .skipPlayingSound
304
; when the last delay was a multiple of 4, play a sound if there is one
305
ld a, [wPlayerSpinInPlaceAnimSoundID]
306
cp $ff
307
call nz, PlaySound
308
.skipPlayingSound
309
ld a, [wPlayerSpinInPlaceAnimFrameDelayDelta]
310
add c
311
ld [wPlayerSpinInPlaceAnimFrameDelay], a
312
ld c, a
313
ld a, [wPlayerSpinInPlaceAnimFrameDelayEndValue]
314
cp c
315
ret z
316
call DelayFrames
317
jr PlayerSpinInPlace
318
319
PlayerSpinWhileMovingUpOrDown:
320
call SpinPlayerSprite
321
ld a, [wPlayerSpinWhileMovingUpOrDownAnimDeltaY]
322
ld c, a
323
ld a, [wSpritePlayerStateData1YPixels]
324
add c
325
ld [wSpritePlayerStateData1YPixels], a
326
ld c, a
327
ld a, [wPlayerSpinWhileMovingUpOrDownAnimMaxY]
328
cp c
329
ret z
330
ld a, [wPlayerSpinWhileMovingUpOrDownAnimFrameDelay]
331
ld c, a
332
call DelayFrames
333
jr PlayerSpinWhileMovingUpOrDown
334
335
RestoreFacingDirectionAndYScreenPos:
336
ld a, [wSavedPlayerScreenY]
337
ld [wSpritePlayerStateData1YPixels], a
338
ld a, [wSavedPlayerFacingDirection]
339
ld [wSpritePlayerStateData1ImageIndex], a ; (image index is locked to standing images)
340
ret
341
342
; if SGB, 2 frames, else 3 frames
343
GetPlayerTeleportAnimFrameDelay:
344
ld a, [wOnSGB]
345
xor $1
346
inc a
347
inc a
348
ret
349
350
IsPlayerStandingOnWarpPadOrHole::
351
ld b, 0
352
ld hl, WarpPadAndHoleData
353
ld a, [wCurMapTileset]
354
ld c, a
355
.loop
356
ld a, [hli]
357
cp $ff
358
jr z, .done
359
cp c
360
jr nz, .nextEntry
361
lda_coord 8, 9
362
cp [hl]
363
jr z, .foundMatch
364
.nextEntry
365
inc hl
366
inc hl
367
jr .loop
368
.foundMatch
369
inc hl
370
ld b, [hl]
371
.done
372
ld a, b
373
ld [wStandingOnWarpPadOrHole], a
374
ret
375
376
INCLUDE "data/tilesets/warp_pad_hole_tile_ids.asm"
377
378
FishingAnim:
379
ld c, 10
380
call DelayFrames
381
ld hl, wMovementFlags
382
set BIT_LEDGE_OR_FISHING, [hl]
383
ld de, RedSprite
384
ld hl, vNPCSprites tile $00
385
lb bc, BANK(RedSprite), 12
386
call CopyVideoData
387
ld a, $4
388
ld hl, RedFishingTiles
389
call LoadAnimSpriteGfx
390
ld a, [wSpritePlayerStateData1ImageIndex]
391
ld c, a
392
ld b, $0
393
ld hl, FishingRodOAM
394
add hl, bc
395
ld de, wShadowOAMSprite39
396
ld bc, $4
397
call CopyData
398
ld c, 100
399
call DelayFrames
400
ld a, [wRodResponse]
401
and a
402
ld hl, NoNibbleText
403
jr z, .done
404
cp $2
405
ld hl, NothingHereText
406
jr z, .done
407
408
; there was a bite
409
410
; shake the player's sprite vertically
411
ld b, 10
412
.loop
413
ld hl, wSpritePlayerStateData1YPixels
414
call .ShakePlayerSprite
415
ld hl, wShadowOAMSprite39
416
call .ShakePlayerSprite
417
call Delay3
418
dec b
419
jr nz, .loop
420
421
; If the player is facing up, hide the fishing rod so it doesn't overlap with
422
; the exclamation bubble that will be shown next.
423
ld a, [wSpritePlayerStateData1ImageIndex] ; (image index is locked to standing images)
424
cp SPRITE_FACING_UP
425
jr nz, .skipHidingFishingRod
426
ld a, $a0
427
ld [wShadowOAMSprite39YCoord], a
428
429
.skipHidingFishingRod
430
ld hl, wEmotionBubbleSpriteIndex
431
xor a
432
ld [hli], a ; player's sprite
433
ld [hl], a ; EXCLAMATION_BUBBLE
434
predef EmotionBubble
435
436
; If the player is facing up, unhide the fishing rod.
437
ld a, [wSpritePlayerStateData1ImageIndex] ; (image index is locked to standing images)
438
cp SPRITE_FACING_UP
439
jr nz, .skipUnhidingFishingRod
440
ld a, $44
441
ld [wShadowOAMSprite39YCoord], a
442
443
.skipUnhidingFishingRod
444
ld hl, ItsABiteText
445
446
.done
447
call PrintText
448
ld hl, wMovementFlags
449
res BIT_LEDGE_OR_FISHING, [hl]
450
call LoadFontTilePatterns
451
ret
452
453
.ShakePlayerSprite
454
ld a, [hl]
455
xor $1
456
ld [hl], a
457
ret
458
459
NoNibbleText:
460
text_far _NoNibbleText
461
text_end
462
463
NothingHereText:
464
text_far _NothingHereText
465
text_end
466
467
ItsABiteText:
468
text_far _ItsABiteText
469
text_end
470
471
FishingRodOAM:
472
; specifies how the fishing rod should be drawn on the screen
473
dbsprite 9, 11, 4, 3, $fd, 0 ; down
474
dbsprite 9, 8, 4, 4, $fd, 0 ; up
475
dbsprite 8, 10, 0, 0, $fe, 0 ; left
476
dbsprite 11, 10, 0, 0, $fe, OAM_XFLIP ; right
477
478
MACRO fishing_gfx
479
dw \1
480
db \2
481
db BANK(\1)
482
dw vNPCSprites tile \3
483
ENDM
484
485
RedFishingTiles:
486
fishing_gfx RedFishingTilesFront, 2, $02
487
fishing_gfx RedFishingTilesBack, 2, $06
488
fishing_gfx RedFishingTilesSide, 2, $0a
489
fishing_gfx RedFishingRodTiles, 3, $fd
490
491
_HandleMidJump::
492
ld a, [wPlayerJumpingYScreenCoordsIndex]
493
ld c, a
494
inc a
495
cp $10
496
jr nc, .finishedJump
497
ld [wPlayerJumpingYScreenCoordsIndex], a
498
ld b, 0
499
ld hl, PlayerJumpingYScreenCoords
500
add hl, bc
501
ld a, [hl]
502
ld [wSpritePlayerStateData1YPixels], a
503
ret
504
.finishedJump
505
ld a, [wWalkCounter]
506
cp 0
507
ret nz
508
call UpdateSprites
509
call Delay3
510
xor a
511
ldh [hJoyHeld], a
512
ldh [hJoyPressed], a
513
ldh [hJoyReleased], a
514
ld [wPlayerJumpingYScreenCoordsIndex], a
515
ld hl, wMovementFlags
516
res BIT_LEDGE_OR_FISHING, [hl]
517
ld hl, wStatusFlags5
518
res BIT_SCRIPTED_MOVEMENT_STATE, [hl]
519
xor a
520
ld [wJoyIgnore], a
521
ret
522
523
PlayerJumpingYScreenCoords:
524
; Sequence of y screen coordinates for player's sprite when jumping over a ledge.
525
db $38, $36, $34, $32, $31, $30, $30, $30, $31, $32, $33, $34, $36, $38, $3C, $3C
526
527