-
Notifications
You must be signed in to change notification settings - Fork 0
/
opening_screen.c
222 lines (192 loc) · 5.88 KB
/
opening_screen.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
/*
* StickGBC by Matt Comben is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
* To view a copy of this license, visit
* http://creativecommons.org/licenses/by-nc-nd/4.0/.
*/
#pragma bank=7
#include "opening_screen.h"
#include "opening_screen_map.h"
#include "opening_screen_palette.h"
#include "opening_screen_tiles.h"
#include "splash_screen_map.h"
#include "splash_screen_tiles.h"
#include "splash_screen_palette.h"
#include "game_constants.h"
#include "main.h"
void splash_screen_loop()
{
DISPLAY_OFF;
HIDE_SPRITES;
HIDE_WIN;
screen_state.background_color_palette = splash_screen_palette;
screen_state.background_tile_map = splashscreenmap;
screen_state.background_tiles = splashscreentiles;
screen_state.background_width = splashscreenmapWidth;
screen_state.draw_offset_x = 0U;
screen_state.draw_offset_y = 0U;
screen_state.draw_max_x = SCREEN_WIDTH_TILES;
screen_state.draw_max_y = SCREEN_HEIGHT_TILES;
set_background_tiles(
ROM_BANK_OPENING_SCREEN,
ROM_BANK_OPENING_SCREEN,
ROM_BANK_OPENING_SCREEN, // Load tiles from this ROM bank
ROM_BANK_OPENING_SCREEN // Return to the ROM bank for this function
);
// Move background to top left
move_bkg(0, 0);
// Load additional tiles required
set_bkg_data(8U, 120U, &(splashscreentiles[8U << 4]));
VBK_REG = 1;
set_bkg_data(0U, 25U, &(splashscreentiles[128U << 4]));
VBK_REG = 0;
DISPLAY_ON;
// Reset values for currently pressed buttons
joypad_state.a_pressed = 0U;
joypad_state.start_pressed = 0U;
// Wait for user to press A or START
while (joypad_state.a_pressed == 0U && joypad_state.start_pressed == 0U)
{
wait_vbl_done();
main_check_joy(ROM_BANK_OPENING_SCREEN);
}
}
/* opening_screen_update_selection
*
* Checks joypad input to update selected option
* and redraws tile selection palettes.
*
* @param Currently selected option
*
* @returns new selected option index
*/
UINT8 opening_scrn_update_sel(UINT8 selected_option)
{
UINT8 itx;
UINT8 tile_itx_x;
UINT8 tile_itx_y;
unsigned char original_data;
if (joypad_state.travel_x == 1)
{
// Set first bit to 1
selected_option |= 1U;
}
if (joypad_state.travel_x == -1)
{
// Set first bit to 0 (mask second bit)
selected_option &= 0x2U;
}
if (joypad_state.travel_y == 1)
{
// Set second bit to 1
selected_option |= 2U;
}
if (joypad_state.travel_y == -1)
{
// Set second bit to 0 (mask first bit)
selected_option &= 0x1U;
}
// Update palette for selection options
VBK_REG = 1;
for (itx = 0; itx != 4; itx ++)
{
for (tile_itx_x = 0; tile_itx_x != 6; tile_itx_x ++)
{
for (tile_itx_y = 0; tile_itx_y != 3; tile_itx_y ++)
{
get_bkg_tiles(
2U + ((itx % 2) * 10U) + tile_itx_x,
8U + ((itx / 2) * 5U) + tile_itx_y,
1U,
1U,
&original_data
);
// Set palette to 0
original_data &= 0xF8;
if (itx == selected_option)
{
// Increment palette to 1
original_data += 1U;
}
set_bkg_tiles(
2U + ((itx % 2) * 10U) + tile_itx_x,
8U + ((itx / 2) * 5U) + tile_itx_y,
1U,
1U,
&original_data
);
}
}
}
VBK_REG = 0;
return selected_option;
}
void opening_screen_loop()
{
BOOLEAN last_input_had_input;
UINT8 selected_option = 0;
DISPLAY_OFF;
screen_state.background_color_palette = opening_screen_palette;
screen_state.background_tile_map = openingscreenmap;
screen_state.background_tiles = openingscreentiles;
screen_state.background_width = openingscreenmapWidth;
screen_state.draw_offset_x = 0U;
screen_state.draw_offset_y = 0U;
screen_state.draw_max_x = SCREEN_WIDTH_TILES;
screen_state.draw_max_y = SCREEN_HEIGHT_TILES;
set_background_tiles(
ROM_BANK_OPENING_SCREEN,
ROM_BANK_OPENING_SCREEN,
ROM_BANK_OPENING_SCREEN, // Load tiles from this ROM bank
ROM_BANK_OPENING_SCREEN // Return to the ROM bank for this function
);
// Move background to top left
move_bkg(0, 0);
// Load additional tiles required
set_bkg_data(8U, 44U, &(openingscreentiles[8U << 4]));
DISPLAY_ON;
// Set joypad state to no input
joypad_state.a_pressed = 0U;
joypad_state.start_pressed = 0U;
joypad_state.travel_x = 0;
joypad_state.travel_y = 0;
last_input_had_input = 0U;
// Set initial option to 30 days
selected_option = 1U;
opening_scrn_update_sel(selected_option);
// Wait for user to press A or START
while (joypad_state.a_pressed == 0U && joypad_state.start_pressed == 0U)
{
// Check for user changing selection
if (joypad_state.travel_x != 0 || joypad_state.travel_y != 0)
{
// Only update if they've just pressed the button
if (last_input_had_input == 0U)
{
selected_option = opening_scrn_update_sel(selected_option);
}
}
else
{
last_input_had_input = 0U;
}
wait_vbl_done();
main_check_joy(ROM_BANK_OPENING_SCREEN);
}
// Update game_state max_days based on selected input
if (selected_option == 0U)
{
game_state.max_days = 15U;
}
else if (selected_option == 1U)
{
game_state.max_days = 30U;
}
else if (selected_option == 2U)
{
game_state.max_days = 100U;
}
else if (selected_option == 3U)
{
game_state.max_days = 0U;
}
}