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