Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/overworld/player_state.asm
1271 views
1
; only used for setting BIT_STANDING_ON_WARP of wMovementFlags upon entering a new map
2
IsPlayerStandingOnWarp::
3
ld a, [wNumberOfWarps]
4
and a
5
ret z
6
ld c, a
7
ld hl, wWarpEntries
8
.loop
9
ld a, [wYCoord]
10
cp [hl]
11
jr nz, .nextWarp1
12
inc hl
13
ld a, [wXCoord]
14
cp [hl]
15
jr nz, .nextWarp2
16
inc hl
17
ld a, [hli] ; target warp
18
ld [wDestinationWarpID], a
19
ld a, [hl] ; target map
20
ldh [hWarpDestinationMap], a
21
ld hl, wMovementFlags
22
set BIT_STANDING_ON_WARP, [hl]
23
ret
24
.nextWarp1
25
inc hl
26
.nextWarp2
27
inc hl
28
inc hl
29
inc hl
30
dec c
31
jr nz, .loop
32
ret
33
34
CheckForceBikeOrSurf::
35
ld hl, wStatusFlags6
36
bit BIT_ALWAYS_ON_BIKE, [hl]
37
ret nz
38
ld hl, ForcedBikeOrSurfMaps
39
ld a, [wYCoord]
40
ld b, a
41
ld a, [wXCoord]
42
ld c, a
43
ld a, [wCurMap]
44
ld d, a
45
.loop
46
ld a, [hli]
47
cp $ff
48
ret z ; if we reach FF then it's not part of the list
49
cp d ; compare to current map
50
jr nz, .incorrectMap
51
ld a, [hli]
52
cp b ; compare y-coord
53
jr nz, .incorrectY
54
ld a, [hli]
55
cp c ; compare x-coord
56
jr nz, .loop ; incorrect x-coord, check next item
57
ld a, [wCurMap]
58
cp SEAFOAM_ISLANDS_B3F
59
ld a, SCRIPT_SEAFOAMISLANDSB3F_MOVE_OBJECT
60
ld [wSeafoamIslandsB3FCurScript], a
61
jr z, .forceSurfing
62
ld a, [wCurMap]
63
cp SEAFOAM_ISLANDS_B4F
64
ld a, SCRIPT_SEAFOAMISLANDSB4F_MOVE_OBJECT
65
ld [wSeafoamIslandsB4FCurScript], a
66
jr z, .forceSurfing
67
ld hl, wStatusFlags6
68
set BIT_ALWAYS_ON_BIKE, [hl]
69
ld a, $1
70
ld [wWalkBikeSurfState], a
71
ld [wWalkBikeSurfStateCopy], a
72
jp ForceBikeOrSurf
73
.incorrectMap
74
inc hl
75
.incorrectY
76
inc hl
77
jr .loop
78
.forceSurfing
79
ld a, $2
80
ld [wWalkBikeSurfState], a
81
ld [wWalkBikeSurfStateCopy], a
82
jp ForceBikeOrSurf
83
84
INCLUDE "data/maps/force_bike_surf.asm"
85
86
IsPlayerFacingEdgeOfMap::
87
push hl
88
push de
89
push bc
90
ld a, [wSpritePlayerStateData1FacingDirection]
91
srl a
92
ld c, a
93
ld b, $0
94
ld hl, .functionPointerTable
95
add hl, bc
96
ld a, [hli]
97
ld h, [hl]
98
ld l, a
99
ld a, [wYCoord]
100
ld b, a
101
ld a, [wXCoord]
102
ld c, a
103
ld de, .return
104
push de
105
jp hl
106
.return
107
pop bc
108
pop de
109
pop hl
110
ret
111
112
.functionPointerTable
113
dw .facingDown
114
dw .facingUp
115
dw .facingLeft
116
dw .facingRight
117
118
.facingDown
119
ld a, [wCurMapHeight]
120
add a
121
dec a
122
cp b
123
jr z, .setCarry
124
jr .resetCarry
125
126
.facingUp
127
ld a, b
128
and a
129
jr z, .setCarry
130
jr .resetCarry
131
132
.facingLeft
133
ld a, c
134
and a
135
jr z, .setCarry
136
jr .resetCarry
137
138
.facingRight
139
ld a, [wCurMapWidth]
140
add a
141
dec a
142
cp c
143
jr z, .setCarry
144
jr .resetCarry
145
.resetCarry
146
and a
147
ret
148
.setCarry
149
scf
150
ret
151
152
IsWarpTileInFrontOfPlayer::
153
push hl
154
push de
155
push bc
156
call _GetTileAndCoordsInFrontOfPlayer
157
ld a, [wCurMap]
158
cp SS_ANNE_BOW
159
jr z, IsSSAnneBowWarpTileInFrontOfPlayer
160
ld a, [wSpritePlayerStateData1FacingDirection]
161
srl a
162
ld c, a
163
ld b, 0
164
ld hl, WarpTileListPointers
165
add hl, bc
166
ld a, [hli]
167
ld h, [hl]
168
ld l, a
169
ld a, [wTileInFrontOfPlayer]
170
ld de, $1
171
call IsInArray
172
.done
173
pop bc
174
pop de
175
pop hl
176
ret
177
178
INCLUDE "data/tilesets/warp_carpet_tile_ids.asm"
179
180
IsSSAnneBowWarpTileInFrontOfPlayer:
181
ld a, [wTileInFrontOfPlayer]
182
cp $15
183
jr nz, .notSSAnne5Warp
184
scf
185
jr IsWarpTileInFrontOfPlayer.done
186
.notSSAnne5Warp
187
and a
188
jr IsWarpTileInFrontOfPlayer.done
189
190
IsPlayerStandingOnDoorTileOrWarpTile::
191
push hl
192
push de
193
push bc
194
farcall IsPlayerStandingOnDoorTile
195
jr c, .done
196
ld a, [wCurMapTileset]
197
add a
198
ld c, a
199
ld b, $0
200
ld hl, WarpTileIDPointers
201
add hl, bc
202
ld a, [hli]
203
ld h, [hl]
204
ld l, a
205
ld de, $1
206
lda_coord 8, 9
207
call IsInArray
208
jr nc, .done
209
ld hl, wMovementFlags
210
res BIT_STANDING_ON_WARP, [hl]
211
.done
212
pop bc
213
pop de
214
pop hl
215
ret
216
217
INCLUDE "data/tilesets/warp_tile_ids.asm"
218
219
PrintSafariZoneSteps::
220
ld a, [wCurMap]
221
cp SAFARI_ZONE_EAST
222
ret c
223
cp CERULEAN_CAVE_2F
224
ret nc
225
hlcoord 0, 0
226
ld b, 3
227
ld c, 7
228
call TextBoxBorder
229
hlcoord 1, 1
230
ld de, wSafariSteps
231
lb bc, 2, 3
232
call PrintNumber
233
hlcoord 4, 1
234
ld de, SafariSteps
235
call PlaceString
236
hlcoord 1, 3
237
ld de, SafariBallText
238
call PlaceString
239
ld a, [wNumSafariBalls]
240
cp 10
241
jr nc, .tenOrMore
242
hlcoord 5, 3
243
ld a, " "
244
ld [hl], a
245
.tenOrMore
246
hlcoord 6, 3
247
ld de, wNumSafariBalls
248
lb bc, 1, 2
249
jp PrintNumber
250
251
SafariSteps:
252
db "/500@"
253
254
SafariBallText:
255
db "BALL×× @"
256
257
GetTileAndCoordsInFrontOfPlayer:
258
call GetPredefRegisters
259
260
_GetTileAndCoordsInFrontOfPlayer:
261
ld a, [wYCoord]
262
ld d, a
263
ld a, [wXCoord]
264
ld e, a
265
ld a, [wSpritePlayerStateData1FacingDirection]
266
and a ; cp SPRITE_FACING_DOWN
267
jr nz, .notFacingDown
268
; facing down
269
lda_coord 8, 11
270
inc d
271
jr .storeTile
272
.notFacingDown
273
cp SPRITE_FACING_UP
274
jr nz, .notFacingUp
275
; facing up
276
lda_coord 8, 7
277
dec d
278
jr .storeTile
279
.notFacingUp
280
cp SPRITE_FACING_LEFT
281
jr nz, .notFacingLeft
282
; facing left
283
lda_coord 6, 9
284
dec e
285
jr .storeTile
286
.notFacingLeft
287
cp SPRITE_FACING_RIGHT
288
jr nz, .storeTile
289
; facing right
290
lda_coord 10, 9
291
inc e
292
.storeTile
293
ld c, a
294
ld [wTileInFrontOfPlayer], a
295
ret
296
297
; hPlayerFacing
298
const_def
299
const BIT_FACING_DOWN ; 0
300
const BIT_FACING_UP ; 1
301
const BIT_FACING_LEFT ; 2
302
const BIT_FACING_RIGHT ; 3
303
304
GetTileTwoStepsInFrontOfPlayer:
305
xor a
306
ldh [hPlayerFacing], a
307
ld hl, wYCoord
308
ld a, [hli]
309
ld d, a
310
ld e, [hl]
311
ld a, [wSpritePlayerStateData1FacingDirection]
312
and a ; cp SPRITE_FACING_DOWN
313
jr nz, .notFacingDown
314
; facing down
315
ld hl, hPlayerFacing
316
set BIT_FACING_DOWN, [hl]
317
lda_coord 8, 13
318
inc d
319
jr .storeTile
320
.notFacingDown
321
cp SPRITE_FACING_UP
322
jr nz, .notFacingUp
323
; facing up
324
ld hl, hPlayerFacing
325
set BIT_FACING_UP, [hl]
326
lda_coord 8, 5
327
dec d
328
jr .storeTile
329
.notFacingUp
330
cp SPRITE_FACING_LEFT
331
jr nz, .notFacingLeft
332
; facing left
333
ld hl, hPlayerFacing
334
set BIT_FACING_LEFT, [hl]
335
lda_coord 4, 9
336
dec e
337
jr .storeTile
338
.notFacingLeft
339
cp SPRITE_FACING_RIGHT
340
jr nz, .storeTile
341
; facing right
342
ld hl, hPlayerFacing
343
set BIT_FACING_RIGHT, [hl]
344
lda_coord 12, 9
345
inc e
346
.storeTile
347
ld c, a
348
ld [wTileInFrontOfBoulderAndBoulderCollisionResult], a
349
ld [wTileInFrontOfPlayer], a
350
ret
351
352
CheckForCollisionWhenPushingBoulder:
353
call GetTileTwoStepsInFrontOfPlayer
354
ld hl, wTilesetCollisionPtr
355
ld a, [hli]
356
ld h, [hl]
357
ld l, a
358
.loop
359
ld a, [hli]
360
cp $ff
361
jr z, .done ; if the tile two steps ahead is not passable
362
cp c
363
jr nz, .loop
364
ld hl, TilePairCollisionsLand
365
call CheckForTilePairCollisions2
366
ld a, $ff
367
jr c, .done ; if there is an elevation difference between the current tile and the one two steps ahead
368
ld a, [wTileInFrontOfBoulderAndBoulderCollisionResult]
369
cp $15 ; stairs tile
370
ld a, $ff
371
jr z, .done ; if the tile two steps ahead is stairs
372
call CheckForBoulderCollisionWithSprites
373
.done
374
ld [wTileInFrontOfBoulderAndBoulderCollisionResult], a
375
ret
376
377
; sets a to $ff if there is a collision and $00 if there is no collision
378
CheckForBoulderCollisionWithSprites:
379
ld a, [wBoulderSpriteIndex]
380
dec a
381
swap a
382
ld d, 0
383
ld e, a
384
ld hl, wSprite01StateData2MapY
385
add hl, de
386
ld a, [hli] ; map Y position
387
ldh [hPlayerYCoord], a
388
ld a, [hl] ; map X position
389
ldh [hPlayerXCoord], a
390
ld a, [wNumSprites]
391
ld c, a
392
ld de, $f
393
ld hl, wSprite01StateData2MapY
394
ldh a, [hPlayerFacing]
395
and (1 << BIT_FACING_UP) | (1 << BIT_FACING_DOWN)
396
jr z, .pushingHorizontallyLoop
397
.pushingVerticallyLoop
398
inc hl
399
ldh a, [hPlayerXCoord]
400
cp [hl]
401
jr nz, .nextSprite1 ; if X coordinates don't match
402
dec hl
403
ld a, [hli]
404
ld b, a
405
ldh a, [hPlayerFacing]
406
ASSERT BIT_FACING_DOWN == 0
407
rrca
408
jr c, .pushingDown
409
; pushing up
410
ldh a, [hPlayerYCoord]
411
dec a
412
jr .compareYCoords
413
.pushingDown
414
ldh a, [hPlayerYCoord]
415
inc a
416
.compareYCoords
417
cp b
418
jr z, .failure
419
.nextSprite1
420
dec c
421
jr z, .success
422
add hl, de
423
jr .pushingVerticallyLoop
424
.pushingHorizontallyLoop
425
ld a, [hli]
426
ld b, a
427
ldh a, [hPlayerYCoord]
428
cp b
429
jr nz, .nextSprite2
430
ld b, [hl]
431
ldh a, [hPlayerFacing]
432
bit BIT_FACING_LEFT, a
433
jr nz, .pushingLeft
434
; pushing right
435
ldh a, [hPlayerXCoord]
436
inc a
437
jr .compareXCoords
438
.pushingLeft
439
ldh a, [hPlayerXCoord]
440
dec a
441
.compareXCoords
442
cp b
443
jr z, .failure
444
.nextSprite2
445
dec c
446
jr z, .success
447
add hl, de
448
jr .pushingHorizontallyLoop
449
.failure
450
ld a, $ff
451
ret
452
.success
453
xor a
454
ret
455
456