PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/engine/overworld/player_animations.asm

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