cut.asm 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. UsedCut:
  2. xor a
  3. ld [wActionResultOrTookBattleTurn], a ; initialise to failure value
  4. ld a, [wCurMapTileset]
  5. and a ; OVERWORLD
  6. jr z, .overworld
  7. cp GYM
  8. jr nz, .nothingToCut
  9. ld a, [wTileInFrontOfPlayer]
  10. cp $50 ; gym cut tree
  11. jr nz, .nothingToCut
  12. jr .canCut
  13. .overworld
  14. dec a
  15. ld a, [wTileInFrontOfPlayer]
  16. cp $3d ; cut tree
  17. jr z, .canCut
  18. cp $52 ; grass
  19. jr z, .canCut
  20. .nothingToCut
  21. ld hl, .NothingToCutText
  22. jp PrintText
  23. .NothingToCutText
  24. TX_FAR _NothingToCutText
  25. db "@"
  26. .canCut
  27. ld [wCutTile], a
  28. ld a, 1
  29. ld [wActionResultOrTookBattleTurn], a ; used cut
  30. ld a, [wWhichPokemon]
  31. ld hl, wPartyMonNicks
  32. call GetPartyMonName
  33. ld hl, wd730
  34. set 6, [hl]
  35. call GBPalWhiteOutWithDelay3
  36. call ClearSprites
  37. call RestoreScreenTilesAndReloadTilePatterns
  38. ld a, SCREEN_HEIGHT_PIXELS
  39. ld [hWY], a
  40. call Delay3
  41. call LoadGBPal
  42. call LoadCurrentMapView
  43. call SaveScreenTilesToBuffer2
  44. call Delay3
  45. xor a
  46. ld [hWY], a
  47. ld hl, UsedCutText
  48. call PrintText
  49. call LoadScreenTilesFromBuffer2
  50. ld hl, wd730
  51. res 6, [hl]
  52. ld a, $ff
  53. ld [wUpdateSpritesEnabled], a
  54. call InitCutAnimOAM
  55. ld de, CutTreeBlockSwaps
  56. call ReplaceTreeTileBlock
  57. call RedrawMapView
  58. callba AnimCut
  59. ld a, $1
  60. ld [wUpdateSpritesEnabled], a
  61. ld a, SFX_CUT
  62. call PlaySound
  63. ld a, $90
  64. ld [hWY], a
  65. call UpdateSprites
  66. jp RedrawMapView
  67. UsedCutText:
  68. TX_FAR _UsedCutText
  69. db "@"
  70. InitCutAnimOAM:
  71. xor a
  72. ld [wWhichAnimationOffsets], a
  73. ld a, %11100100
  74. ld [rOBP1], a
  75. ld a, [wCutTile]
  76. cp $52
  77. jr z, .grass
  78. ; tree
  79. ld de, Overworld_GFX + $2d0 ; cuttable tree sprite top row
  80. ld hl, vChars1 + $7c0
  81. lb bc, BANK(Overworld_GFX), $02
  82. call CopyVideoData
  83. ld de, Overworld_GFX + $3d0 ; cuttable tree sprite bottom row
  84. ld hl, vChars1 + $7e0
  85. lb bc, BANK(Overworld_GFX), $02
  86. call CopyVideoData
  87. jr WriteCutOrBoulderDustAnimationOAMBlock
  88. .grass
  89. ld hl, vChars1 + $7c0
  90. call LoadCutGrassAnimationTilePattern
  91. ld hl, vChars1 + $7d0
  92. call LoadCutGrassAnimationTilePattern
  93. ld hl, vChars1 + $7e0
  94. call LoadCutGrassAnimationTilePattern
  95. ld hl, vChars1 + $7f0
  96. call LoadCutGrassAnimationTilePattern
  97. call WriteCutOrBoulderDustAnimationOAMBlock
  98. ld hl, wOAMBuffer + $93
  99. ld de, 4
  100. ld a, $30
  101. ld c, e
  102. .loop
  103. ld [hl], a
  104. add hl, de
  105. xor $60
  106. dec c
  107. jr nz, .loop
  108. ret
  109. LoadCutGrassAnimationTilePattern:
  110. ld de, AnimationTileset2 + $60 ; tile depicting a leaf
  111. lb bc, BANK(AnimationTileset2), $01
  112. jp CopyVideoData
  113. WriteCutOrBoulderDustAnimationOAMBlock:
  114. call GetCutOrBoulderDustAnimationOffsets
  115. ld a, $9
  116. ld de, CutOrBoulderDustAnimationTilesAndAttributes
  117. jp WriteOAMBlock
  118. CutOrBoulderDustAnimationTilesAndAttributes:
  119. db $FC,$10,$FD,$10
  120. db $FE,$10,$FF,$10
  121. GetCutOrBoulderDustAnimationOffsets:
  122. ld hl, wSpriteStateData1 + 4
  123. ld a, [hli] ; player's sprite screen Y position
  124. ld b, a
  125. inc hl
  126. ld a, [hli] ; player's sprite screen X position
  127. ld c, a ; bc holds ypos/xpos of player's sprite
  128. inc hl
  129. inc hl
  130. ld a, [hl] ; a holds direction of player (00: down, 04: up, 08: left, 0C: right)
  131. srl a
  132. ld e, a
  133. ld d, $0 ; de holds direction (00: down, 02: up, 04: left, 06: right)
  134. ld a, [wWhichAnimationOffsets]
  135. and a
  136. ld hl, CutAnimationOffsets
  137. jr z, .next
  138. ld hl, BoulderDustAnimationOffsets
  139. .next
  140. add hl, de
  141. ld e, [hl]
  142. inc hl
  143. ld d, [hl]
  144. ld a, b
  145. add d
  146. ld b, a
  147. ld a, c
  148. add e
  149. ld c, a
  150. ret
  151. CutAnimationOffsets:
  152. ; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn
  153. db 8, 36 ; player is facing down
  154. db 8, 4 ; player is facing up
  155. db -8, 20 ; player is facing left
  156. db 24, 20 ; player is facing right
  157. BoulderDustAnimationOffsets:
  158. ; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn
  159. ; These offsets represent 2 blocks away from the player
  160. db 8, 52 ; player is facing down
  161. db 8, -12 ; player is facing up
  162. db -24, 20 ; player is facing left
  163. db 40, 20 ; player is facing right
  164. ReplaceTreeTileBlock:
  165. ; Determine the address of the tile block that contains the tile in front of the
  166. ; player (i.e. where the tree is) and replace it with the corresponding tile
  167. ; block that doesn't have the tree.
  168. push de
  169. ld a, [wCurMapWidth]
  170. add 6
  171. ld c, a
  172. ld b, 0
  173. ld d, 0
  174. ld hl, wCurrentTileBlockMapViewPointer
  175. ld a, [hli]
  176. ld h, [hl]
  177. ld l, a
  178. add hl, bc
  179. ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
  180. and a
  181. jr z, .down
  182. cp SPRITE_FACING_UP
  183. jr z, .up
  184. cp SPRITE_FACING_LEFT
  185. jr z, .left
  186. ; right
  187. ld a, [wXBlockCoord]
  188. and a
  189. jr z, .centerTileBlock
  190. jr .rightOfCenter
  191. .down
  192. ld a, [wYBlockCoord]
  193. and a
  194. jr z, .centerTileBlock
  195. jr .belowCenter
  196. .up
  197. ld a, [wYBlockCoord]
  198. and a
  199. jr z, .aboveCenter
  200. jr .centerTileBlock
  201. .left
  202. ld a, [wXBlockCoord]
  203. and a
  204. jr z, .leftOfCenter
  205. jr .centerTileBlock
  206. .belowCenter
  207. add hl, bc
  208. .centerTileBlock
  209. add hl, bc
  210. .aboveCenter
  211. ld e, $2
  212. add hl, de
  213. jr .next
  214. .leftOfCenter
  215. ld e, $1
  216. add hl, bc
  217. add hl, de
  218. jr .next
  219. .rightOfCenter
  220. ld e, $3
  221. add hl, bc
  222. add hl, de
  223. .next
  224. pop de
  225. ld a, [hl]
  226. ld c, a
  227. .loop ; find the matching tile block in the array
  228. ld a, [de]
  229. inc de
  230. inc de
  231. cp $ff
  232. ret z
  233. cp c
  234. jr nz, .loop
  235. dec de
  236. ld a, [de] ; replacement tile block from matching array entry
  237. ld [hl], a
  238. ret
  239. CutTreeBlockSwaps:
  240. ; first byte = tileset block containing the cut tree
  241. ; second byte = corresponding tileset block after the cut animation happens
  242. db $32, $6D
  243. db $33, $6C
  244. db $34, $6F
  245. db $35, $4C
  246. db $60, $6E
  247. db $0B, $0A
  248. db $3C, $35
  249. db $3F, $35
  250. db $3D, $36
  251. db $FF ; list terminator