Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/events/hidden_objects/cinnabar_gym_quiz.asm
1271 views
1
PrintCinnabarQuiz:
2
ld a, [wSpritePlayerStateData1FacingDirection]
3
cp SPRITE_FACING_UP
4
ret nz
5
call EnableAutoTextBoxDrawing
6
tx_pre_jump CinnabarGymQuiz
7
8
CinnabarGymQuiz::
9
text_asm
10
xor a
11
ld [wOpponentAfterWrongAnswer], a
12
ld a, [wHiddenObjectFunctionArgument]
13
push af
14
and $f
15
ldh [hGymGateIndex], a
16
pop af
17
and $f0
18
swap a
19
ldh [hGymGateAnswer], a
20
ld hl, CinnabarGymQuizIntroText
21
call PrintText
22
ldh a, [hGymGateIndex]
23
dec a
24
add a
25
ld d, 0
26
ld e, a
27
ld hl, CinnabarQuizQuestions
28
add hl, de
29
ld a, [hli]
30
ld h, [hl]
31
ld l, a
32
call PrintText
33
ld a, 1
34
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
35
call CinnabarGymQuiz_AskQuestion
36
jp TextScriptEnd
37
38
CinnabarGymQuizIntroText:
39
text_far _CinnabarGymQuizIntroText
40
text_end
41
42
CinnabarQuizQuestions:
43
dw CinnabarQuizQuestionsText1
44
dw CinnabarQuizQuestionsText2
45
dw CinnabarQuizQuestionsText3
46
dw CinnabarQuizQuestionsText4
47
dw CinnabarQuizQuestionsText5
48
dw CinnabarQuizQuestionsText6
49
50
CinnabarQuizQuestionsText1:
51
text_far _CinnabarQuizQuestionsText1
52
text_end
53
54
CinnabarQuizQuestionsText2:
55
text_far _CinnabarQuizQuestionsText2
56
text_end
57
58
CinnabarQuizQuestionsText3:
59
text_far _CinnabarQuizQuestionsText3
60
text_end
61
62
CinnabarQuizQuestionsText4:
63
text_far _CinnabarQuizQuestionsText4
64
text_end
65
66
CinnabarQuizQuestionsText5:
67
text_far _CinnabarQuizQuestionsText5
68
text_end
69
70
CinnabarQuizQuestionsText6:
71
text_far _CinnabarQuizQuestionsText6
72
text_end
73
74
CinnabarGymGateFlagAction:
75
EventFlagAddress hl, EVENT_CINNABAR_GYM_GATE0_UNLOCKED
76
predef_jump FlagActionPredef
77
78
CinnabarGymQuiz_AskQuestion:
79
call YesNoChoice
80
ldh a, [hGymGateAnswer]
81
ld c, a
82
ld a, [wCurrentMenuItem]
83
cp c
84
jr nz, .wrongAnswer
85
ld hl, wCurrentMapScriptFlags
86
set BIT_CUR_MAP_LOADED_1, [hl]
87
ldh a, [hGymGateIndex]
88
ldh [hBackupGymGateIndex], a
89
ld hl, CinnabarGymQuizCorrectText
90
call PrintText
91
ldh a, [hBackupGymGateIndex]
92
AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
93
ld c, a
94
ld b, FLAG_SET
95
call CinnabarGymGateFlagAction
96
jp UpdateCinnabarGymGateTileBlocks_
97
.wrongAnswer
98
call WaitForSoundToFinish
99
ld a, SFX_DENIED
100
call PlaySound
101
call WaitForSoundToFinish
102
ld hl, CinnabarGymQuizIncorrectText
103
call PrintText
104
ldh a, [hGymGateIndex]
105
add $2
106
AdjustEventBit EVENT_BEAT_CINNABAR_GYM_TRAINER_0, 2
107
ld c, a
108
ld b, FLAG_TEST
109
EventFlagAddress hl, EVENT_BEAT_CINNABAR_GYM_TRAINER_0
110
predef FlagActionPredef
111
ld a, c
112
and a
113
ret nz
114
ldh a, [hGymGateIndex]
115
add $2
116
ld [wOpponentAfterWrongAnswer], a
117
ret
118
119
CinnabarGymQuizCorrectText:
120
sound_get_item_1
121
text_far _CinnabarGymQuizCorrectText
122
text_promptbutton
123
text_asm
124
125
ldh a, [hBackupGymGateIndex]
126
AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
127
ld c, a
128
ld b, FLAG_TEST
129
call CinnabarGymGateFlagAction
130
ld a, c
131
and a
132
jp nz, TextScriptEnd
133
call WaitForSoundToFinish
134
ld a, SFX_GO_INSIDE
135
call PlaySound
136
call WaitForSoundToFinish
137
jp TextScriptEnd
138
139
CinnabarGymQuizIncorrectText:
140
text_far _CinnabarGymQuizIncorrectText
141
text_end
142
143
UpdateCinnabarGymGateTileBlocks_::
144
; Update the overworld map with open floor blocks or locked gate blocks
145
; depending on event flags.
146
ld a, 6
147
ldh [hGymGateIndex], a
148
.loop
149
ldh a, [hGymGateIndex]
150
dec a
151
add a
152
add a
153
ld d, 0
154
ld e, a
155
ld hl, CinnabarGymGateCoords
156
add hl, de
157
ld a, [hli]
158
ld b, [hl]
159
ld c, a
160
inc hl
161
ld a, [hl]
162
ld [wGymGateTileBlock], a
163
push bc
164
ldh a, [hGymGateIndex]
165
ldh [hBackupGymGateIndex], a
166
AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
167
ld c, a
168
ld b, FLAG_TEST
169
call CinnabarGymGateFlagAction
170
ld a, c
171
and a
172
jr nz, .unlocked
173
ld a, [wGymGateTileBlock]
174
jr .next
175
.unlocked
176
ld a, $e
177
.next
178
pop bc
179
ld [wNewTileBlockID], a
180
predef ReplaceTileBlock
181
ld hl, hGymGateIndex
182
dec [hl]
183
jr nz, .loop
184
ret
185
186
MACRO gym_gate_coord
187
db \1, \2, \3, 0
188
ENDM
189
190
DEF HORIZONTAL_GATE_BLOCK EQU $54
191
DEF VERTICAL_GATE_BLOCK EQU $5f
192
193
CinnabarGymGateCoords:
194
; x coord, y coord, block id
195
gym_gate_coord 9, 3, HORIZONTAL_GATE_BLOCK
196
gym_gate_coord 6, 3, HORIZONTAL_GATE_BLOCK
197
gym_gate_coord 6, 6, HORIZONTAL_GATE_BLOCK
198
gym_gate_coord 3, 8, VERTICAL_GATE_BLOCK
199
gym_gate_coord 2, 6, HORIZONTAL_GATE_BLOCK
200
gym_gate_coord 2, 3, HORIZONTAL_GATE_BLOCK
201
202