Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/overworld/hidden_objects.asm
1271 views
1
IsPlayerOnDungeonWarp::
2
xor a
3
ld [wWhichDungeonWarp], a
4
ld a, [wStatusFlags3]
5
bit BIT_ON_DUNGEON_WARP, a
6
ret nz
7
call ArePlayerCoordsInArray
8
ret nc
9
ld a, [wCoordIndex]
10
ld [wWhichDungeonWarp], a
11
ld hl, wStatusFlags3
12
set BIT_ON_DUNGEON_WARP, [hl]
13
ld hl, wStatusFlags6
14
set BIT_DUNGEON_WARP, [hl]
15
ret
16
17
; if a hidden object was found, stores $00 in [hDidntFindAnyHiddenObject], else stores $ff
18
CheckForHiddenObject::
19
ld hl, hItemAlreadyFound
20
xor a
21
ld [hli], a ; [hItemAlreadyFound]
22
ld [hli], a ; [hSavedMapTextPtr]
23
ld [hli], a ; [hSavedMapTextPtr + 1]
24
ld [hl], a ; [hDidntFindAnyHiddenObject]
25
ld de, $0
26
ld hl, HiddenObjectMaps
27
.hiddenMapLoop
28
ld a, [hli]
29
ld b, a
30
cp $ff
31
jr z, .noMatch
32
ld a, [wCurMap]
33
cp b
34
jr z, .foundMatchingMap
35
inc de
36
inc de
37
jr .hiddenMapLoop
38
.foundMatchingMap
39
ld hl, HiddenObjectPointers
40
add hl, de
41
ld a, [hli]
42
ld h, [hl]
43
ld l, a
44
push hl
45
ld hl, wHiddenObjectFunctionArgument
46
xor a
47
ld [hli], a
48
ld [hli], a
49
ld [hl], a
50
pop hl
51
.hiddenObjectLoop
52
ld a, [hli]
53
cp $ff
54
jr z, .noMatch
55
ld [wHiddenObjectY], a
56
ld b, a
57
ld a, [hli]
58
ld [wHiddenObjectX], a
59
ld c, a
60
call CheckIfCoordsInFrontOfPlayerMatch
61
ldh a, [hCoordsInFrontOfPlayerMatch]
62
and a
63
jr z, .foundMatchingObject
64
inc hl
65
inc hl
66
inc hl
67
inc hl
68
push hl
69
ld hl, wHiddenObjectIndex
70
inc [hl]
71
pop hl
72
jr .hiddenObjectLoop
73
.foundMatchingObject
74
ld a, [hli]
75
ld [wHiddenObjectFunctionArgument], a
76
ld a, [hli]
77
ld [wHiddenObjectFunctionRomBank], a
78
ld a, [hli]
79
ld h, [hl]
80
ld l, a
81
ret
82
.noMatch
83
ld a, $ff
84
ldh [hDidntFindAnyHiddenObject], a
85
ret
86
87
; checks if the coordinates in front of the player's sprite match Y in b and X in c
88
; [hCoordsInFrontOfPlayerMatch] = $00 if they match, $ff if they don't match
89
CheckIfCoordsInFrontOfPlayerMatch:
90
ld a, [wSpritePlayerStateData1FacingDirection]
91
cp SPRITE_FACING_UP
92
jr z, .facingUp
93
cp SPRITE_FACING_LEFT
94
jr z, .facingLeft
95
cp SPRITE_FACING_RIGHT
96
jr z, .facingRight
97
; facing down
98
ld a, [wYCoord]
99
inc a
100
jr .upDownCommon
101
.facingUp
102
ld a, [wYCoord]
103
dec a
104
.upDownCommon
105
cp b
106
jr nz, .didNotMatch
107
ld a, [wXCoord]
108
cp c
109
jr nz, .didNotMatch
110
jr .matched
111
.facingLeft
112
ld a, [wXCoord]
113
dec a
114
jr .leftRightCommon
115
.facingRight
116
ld a, [wXCoord]
117
inc a
118
.leftRightCommon
119
cp c
120
jr nz, .didNotMatch
121
ld a, [wYCoord]
122
cp b
123
jr nz, .didNotMatch
124
.matched
125
xor a
126
jr .done
127
.didNotMatch
128
ld a, $ff
129
.done
130
ldh [hCoordsInFrontOfPlayerMatch], a
131
ret
132
133
INCLUDE "data/events/hidden_objects.asm"
134
135