Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/overworld/cut.asm
1271 views
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
24
.NothingToCutText
25
text_far _NothingToCutText
26
text_end
27
28
.canCut
29
ld [wCutTile], a
30
ld a, 1
31
ld [wActionResultOrTookBattleTurn], a ; used cut
32
ld a, [wWhichPokemon]
33
ld hl, wPartyMonNicks
34
call GetPartyMonName
35
ld hl, wStatusFlags5
36
set BIT_NO_TEXT_DELAY, [hl]
37
call GBPalWhiteOutWithDelay3
38
call ClearSprites
39
call RestoreScreenTilesAndReloadTilePatterns
40
ld a, SCREEN_HEIGHT_PX
41
ldh [hWY], a
42
call Delay3
43
call LoadGBPal
44
call LoadCurrentMapView
45
call SaveScreenTilesToBuffer2
46
call Delay3
47
xor a
48
ldh [hWY], a
49
ld hl, UsedCutText
50
call PrintText
51
call LoadScreenTilesFromBuffer2
52
ld hl, wStatusFlags5
53
res BIT_NO_TEXT_DELAY, [hl]
54
ld a, $ff
55
ld [wUpdateSpritesEnabled], a
56
call InitCutAnimOAM
57
ld de, CutTreeBlockSwaps
58
call ReplaceTreeTileBlock
59
call RedrawMapView
60
farcall AnimCut
61
ld a, $1
62
ld [wUpdateSpritesEnabled], a
63
ld a, SFX_CUT
64
call PlaySound
65
ld a, $90
66
ldh [hWY], a
67
call UpdateSprites
68
jp RedrawMapView
69
70
UsedCutText:
71
text_far _UsedCutText
72
text_end
73
74
InitCutAnimOAM:
75
xor a
76
ld [wWhichAnimationOffsets], a
77
ld a, %11100100
78
ldh [rOBP1], a
79
ld a, [wCutTile]
80
cp $52
81
jr z, .grass
82
; tree
83
ld de, Overworld_GFX tile $2d ; cuttable tree sprite top row
84
ld hl, vChars1 tile $7c
85
lb bc, BANK(Overworld_GFX), 2
86
call CopyVideoData
87
ld de, Overworld_GFX tile $3d ; cuttable tree sprite bottom row
88
ld hl, vChars1 tile $7e
89
lb bc, BANK(Overworld_GFX), 2
90
call CopyVideoData
91
jr WriteCutOrBoulderDustAnimationOAMBlock
92
.grass
93
ld hl, vChars1 tile $7c
94
call LoadCutGrassAnimationTilePattern
95
ld hl, vChars1 tile $7d
96
call LoadCutGrassAnimationTilePattern
97
ld hl, vChars1 tile $7e
98
call LoadCutGrassAnimationTilePattern
99
ld hl, vChars1 tile $7f
100
call LoadCutGrassAnimationTilePattern
101
call WriteCutOrBoulderDustAnimationOAMBlock
102
ld hl, wShadowOAMSprite36Attributes
103
ld de, 4
104
ld a, $30
105
ld c, e
106
.loop
107
ld [hl], a
108
add hl, de
109
xor $60
110
dec c
111
jr nz, .loop
112
ret
113
114
LoadCutGrassAnimationTilePattern:
115
ld de, MoveAnimationTiles1 tile 6 ; tile depicting a leaf
116
lb bc, BANK(MoveAnimationTiles1), 1
117
jp CopyVideoData
118
119
WriteCutOrBoulderDustAnimationOAMBlock:
120
call GetCutOrBoulderDustAnimationOffsets
121
ld a, $9
122
ld de, .OAMBlock
123
jp WriteOAMBlock
124
125
.OAMBlock:
126
; tile ID, attributes
127
db $fc, OAM_PAL1
128
db $fd, OAM_PAL1
129
db $fe, OAM_PAL1
130
db $ff, OAM_PAL1
131
132
GetCutOrBoulderDustAnimationOffsets:
133
ld hl, wSpritePlayerStateData1YPixels
134
ld a, [hli] ; player's sprite screen Y position
135
ld b, a
136
inc hl
137
ld a, [hli] ; player's sprite screen X position
138
ld c, a ; bc holds ypos/xpos of player's sprite
139
inc hl
140
inc hl
141
ld a, [hl] ; a holds direction of player (00: down, 04: up, 08: left, 0C: right)
142
srl a
143
ld e, a
144
ld d, $0 ; de holds direction (00: down, 02: up, 04: left, 06: right)
145
ld a, [wWhichAnimationOffsets]
146
and a
147
ld hl, CutAnimationOffsets
148
jr z, .next
149
ld hl, BoulderDustAnimationOffsets
150
.next
151
add hl, de
152
ld e, [hl]
153
inc hl
154
ld d, [hl]
155
ld a, b
156
add d
157
ld b, a
158
ld a, c
159
add e
160
ld c, a
161
ret
162
163
CutAnimationOffsets:
164
; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn
165
db 8, 36 ; player is facing down
166
db 8, 4 ; player is facing up
167
db -8, 20 ; player is facing left
168
db 24, 20 ; player is facing right
169
170
BoulderDustAnimationOffsets:
171
; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn
172
; These offsets represent 2 blocks away from the player
173
db 8, 52 ; player is facing down
174
db 8, -12 ; player is facing up
175
db -24, 20 ; player is facing left
176
db 40, 20 ; player is facing right
177
178
ReplaceTreeTileBlock:
179
; Determine the address of the tile block that contains the tile in front of the
180
; player (i.e. where the tree is) and replace it with the corresponding tile
181
; block that doesn't have the tree.
182
push de
183
ld a, [wCurMapWidth]
184
add 6
185
ld c, a
186
ld b, 0
187
ld d, 0
188
ld hl, wCurrentTileBlockMapViewPointer
189
ld a, [hli]
190
ld h, [hl]
191
ld l, a
192
add hl, bc
193
ld a, [wSpritePlayerStateData1FacingDirection]
194
and a
195
jr z, .down
196
cp SPRITE_FACING_UP
197
jr z, .up
198
cp SPRITE_FACING_LEFT
199
jr z, .left
200
; right
201
ld a, [wXBlockCoord]
202
and a
203
jr z, .centerTileBlock
204
jr .rightOfCenter
205
.down
206
ld a, [wYBlockCoord]
207
and a
208
jr z, .centerTileBlock
209
jr .belowCenter
210
.up
211
ld a, [wYBlockCoord]
212
and a
213
jr z, .aboveCenter
214
jr .centerTileBlock
215
.left
216
ld a, [wXBlockCoord]
217
and a
218
jr z, .leftOfCenter
219
jr .centerTileBlock
220
.belowCenter
221
add hl, bc
222
.centerTileBlock
223
add hl, bc
224
.aboveCenter
225
ld e, $2
226
add hl, de
227
jr .next
228
.leftOfCenter
229
ld e, $1
230
add hl, bc
231
add hl, de
232
jr .next
233
.rightOfCenter
234
ld e, $3
235
add hl, bc
236
add hl, de
237
.next
238
pop de
239
ld a, [hl]
240
ld c, a
241
.loop ; find the matching tile block in the array
242
ld a, [de]
243
inc de
244
inc de
245
cp $ff
246
ret z
247
cp c
248
jr nz, .loop
249
dec de
250
ld a, [de] ; replacement tile block from matching array entry
251
ld [hl], a
252
ret
253
254
INCLUDE "data/tilesets/cut_tree_blocks.asm"
255
256