forked from FireEmblemUniverse/fireemblem8u
/
gameoverbgfx.c
258 lines (193 loc) · 6.19 KB
/
gameoverbgfx.c
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
255
256
257
258
#include "global.h"
#include "functions.h"
#include "variables.h"
#include "proc.h"
#include "hardware.h"
#include "gbaio.h"
#include "mu.h"
#include "bmio.h"
#include "soundwrapper.h"
#include "constants/video-global.h"
#include "uiutils.h"
#include "bmlib.h"
/**
* Background effect for the game over screen
* port from fe6@StanHash
*/
/* struct definitions */
struct ProcGameOverScroll {
PROC_HEADER;
/* 29 */ u8 _pad_29[0x34 - 0x29];
/* 34 */ int bg2_xdiff;
/* 38 */ int bg2_ydiff;
/* 3C */ int bg3_xdiff;
/* 40 */ int bg3_ydiff;
/* 44 */ u8 _pad_44[0x64 - 0x44];
/* 64 */ s16 bg2_xpos;
/* 66 */ s16 bg2_ypos;
/* 68 */ s16 bg3_xpos;
/* 6A */ s16 bg3_ypos;
};
struct ProcGameOverScreen {
PROC_HEADER;
/* 29 */ u8 _pad_29[0x4C - 0x29];
/* 4C */ s16 counter1;
/* 4E */ s16 counter2;
};
/* function declarations */
void GameOverScreen_RandomScroll_Init(struct ProcGameOverScroll *proc);
void GameOverScreen_RandomScroll_Loop(struct ProcGameOverScroll *proc);
void GameOverScreen_End(struct ProcGameOverScreen *proc);
void GameOverScreen_Init(struct ProcGameOverScreen *proc);
void GameOverScreen_LoopFadeIn(struct ProcGameOverScreen *proc);
void GameOverScreen_BeginIdle(struct ProcGameOverScreen *proc);
void GameOverScreen_LoopIdle(struct ProcGameOverScreen *proc);
void GameOverScreen_BeginFadeOut(struct ProcGameOverScreen *proc);
void GameOverScreen_LoopFadeOut(struct ProcGameOverScreen *proc);
/* section.data */
extern u16 CONST_DATA Img_GameOverText[];
extern u16 CONST_DATA Img_GameOverText[];
extern u16 CONST_DATA Img_GameOverText[];
extern u16 CONST_DATA Img_GameOverText[];
extern u16 CONST_DATA Img_GameOverText[];
struct ProcCmd CONST_DATA ProcScr_GameOverScreen_RandomScroll[] = {
PROC_CALL(GameOverScreen_RandomScroll_Init),
PROC_REPEAT(GameOverScreen_RandomScroll_Loop),
PROC_END,
};
struct ProcCmd CONST_DATA ProcScr_GameOverScreen[] = {
PROC_SET_END_CB(GameOverScreen_End),
PROC_CALL(GameOverScreen_Init),
PROC_CALL(MU_EndAll),
PROC_START_CHILD(ProcScr_GameOverScreen_RandomScroll),
PROC_REPEAT(GameOverScreen_LoopFadeIn),
PROC_CALL(GameOverScreen_BeginIdle),
PROC_REPEAT(GameOverScreen_LoopIdle),
PROC_LABEL(0x63),
PROC_CALL(GameOverScreen_BeginFadeOut),
PROC_REPEAT(GameOverScreen_LoopFadeOut),
PROC_END,
};
/* section.text */
void GameOverScreen_RandomScroll_Init(struct ProcGameOverScroll *proc)
{
proc->bg2_xdiff = +46;
proc->bg2_ydiff = -90;
proc->bg3_xdiff = -16;
proc->bg3_ydiff = -53;
proc->bg2_xpos = 1234;
proc->bg2_ypos = 5678;
proc->bg3_xpos = 6346;
proc->bg3_ypos = 8536;
}
void GameOverScreen_RandomScroll_Loop(struct ProcGameOverScroll *proc)
{
proc->bg2_xpos += proc->bg2_xdiff;
proc->bg2_ypos += proc->bg2_ydiff;
proc->bg3_xpos += proc->bg3_xdiff;
proc->bg3_ypos += proc->bg3_ydiff;
BG_SetPosition(BG_2, -proc->bg2_xpos >> 8, -proc->bg2_ypos >> 8);
BG_SetPosition(BG_3, -proc->bg3_xpos >> 8, -proc->bg3_ypos >> 8);
}
void GameOverScreenHBlank(void)
{
u16 val = REG_VCOUNT + 1;
if (val > DISPLAY_HEIGHT)
val = 0;
if (val > DISPLAY_HEIGHT/2)
val = DISPLAY_HEIGHT - val;
val = val / 3;
if (val > 0x10)
val = 0x10;
REG_BLDCA = val;
REG_BLDCB = val;
}
void GameOverScreen_Init(struct ProcGameOverScreen *proc)
{
int i;
BMapDispSuspend();
StartBgm(0x3E, 0);
gLCDControlBuffer.bg0cnt.priority = 0;
gLCDControlBuffer.bg1cnt.priority = 1;
gLCDControlBuffer.bg2cnt.priority = 2;
gLCDControlBuffer.bg3cnt.priority = 3;
SetBackgroundTileDataOffset(2, 0);
SetBackgroundTileDataOffset(3, 0);
Decompress(Img_GameOverText, BG_CHR_ADDR(BGCHR_GAMEOVER_TEXT));
ApplyPalette(Pal_GameOverText1, BGPAL_GAMEOVER_4);
Decompress(Img_ChapterIntroFog, BG_CHR_ADDR(BGCHR_BMFX_IMG));
ApplyPalette(Pal_GameOverText2, BGPAL_GAMEOVER_TEXT);
BG_SetPosition(0, 0, 0);
ClearBg0Bg1();
CallARM_FillTileRect(
TILEMAP_LOCATED(gBG0TilemapBuffer, 7, 9),
Tsa_GameOverFx,
TILEREF(BGCHR_GAMEOVER_TEXT, BGPAL_GAMEOVER_TEXT));
PutScreenFogEffectOverlayed();
PutScreenFogEffect();
BG_EnableSyncByMask(BG2_SYNC_BIT + BG3_SYNC_BIT);
SetPrimaryHBlankHandler(GameOverScreenHBlank);
SetBlendConfig(1, 14, 14, 0);
SetBlendTargetA(0, 0, 1, 0, 0);
SetBlendTargetB(0, 0, 0, 1, 0);
MaybeResetSomePal();
MaybeSmoothChangeSomePal(&PAL_BG_COLOR(BGPAL_GAMEOVER_TEXT, 0), BGPAL_GAMEOVER_TEXT, 1, +1);
MaybeSmoothChangeSomePal(&PAL_BG_COLOR(BGPAL_GAMEOVER_4, 0), BGPAL_GAMEOVER_4, 1, +1);
proc->counter1 = 21;
for (i = 0; i < 10; ++i)
CALLARM_ColorFadeTick();
EnablePaletteSync();
}
void GameOverScreen_LoopFadeIn(struct ProcGameOverScreen *proc)
{
if ((GetGameClock() % 8) == 0)
{
CALLARM_ColorFadeTick();
EnablePaletteSync();
proc->counter1--;
if (proc->counter1 < 0)
Proc_Break(proc);
}
}
void GameOverScreen_BeginIdle(struct ProcGameOverScreen *proc)
{
proc->counter2 = 1500;
}
void GameOverScreen_LoopIdle(struct ProcGameOverScreen *proc)
{
proc->counter2--;
if (proc->counter2 < 0)
Proc_Goto(proc, 0x63);
if ((A_BUTTON | B_BUTTON | START_BUTTON) & gKeyStatusPtr->newKeys)
Proc_Goto(proc, 0x63);
}
void GameOverScreen_BeginFadeOut(struct ProcGameOverScreen *proc)
{
MaybeResetSomePal();
MaybeSmoothChangeSomePal(&PAL_BG_COLOR(BGPAL_GAMEOVER_TEXT, 0), BGPAL_GAMEOVER_TEXT, 1, -1);
MaybeSmoothChangeSomePal(&PAL_BG_COLOR(BGPAL_GAMEOVER_4, 0), BGPAL_GAMEOVER_4, 1, -1);
Sound_FadeOutBGM(4);
}
void GameOverScreen_LoopFadeOut(struct ProcGameOverScreen *proc)
{
CALLARM_ColorFadeTick();
EnablePaletteSync();
proc->counter1++;
if (proc->counter1 == 0x20)
Proc_Break(proc);
}
void GameOverScreen_End(struct ProcGameOverScreen *proc)
{
SetPrimaryHBlankHandler(NULL);
SetSecondaryHBlankHandler(NULL);
SetDispEnable(0, 0, 0, 0, 0);
gPaletteBuffer[PAL_BACKDROP_OFFSET] = 0;
EnablePaletteSync();
}
void StartGameOverScreen(ProcPtr parent)
{
if (parent)
Proc_StartBlocking(ProcScr_GameOverScreen, parent);
else
Proc_Start(ProcScr_GameOverScreen, PROC_TREE_3);
}