-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
NewGameAreYouSure.c
211 lines (173 loc) · 6.81 KB
/
NewGameAreYouSure.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
// Filename: NewGameAreYouSure.c
// Contains code for the functions that are specific to the "Are you sure you want to start a new game?" screen.
//
// Project Codename: GameB
// TODO: Come up with a better name later.
// 2020 Joseph Ryan Ries <ryanries09@gmail.com>
// My YouTube series where we program an entire video game from scratch in C.
// Watch it on YouTube: https://www.youtube.com/watch?v=3zFFrBSdBvA
// Follow along on GitHub: https://github.com/ryanries/GameB
// Find me on Twitter @JosephRyanRies
// # License
// ----------
// The source code in this project is licensed under the MIT license.
// The media assets such as artwork, custom fonts, music and sound effects are licensed under a separate license.
// A copy of that license can be found in the 'Assets' directory.
// stb_vorbis by Sean Barrett is public domain and a copy of its license can be found in the stb_vorbis.c file.
#include "CommonMain.h"
#include "Platform.h"
#include "NewGameAreYouSure.h"
MENUITEM gMI_NewGameAreYouSure_Yes = { "Yes", (GAME_RES_WIDTH / 2) - ((3 * 6) / 2), 100, true, MenuItem_NewGameAreYouSure_Yes };
MENUITEM gMI_NewGameAreYouSure_No = { "No", (GAME_RES_WIDTH / 2) - ((2 * 6) / 2), 115, true, MenuItem_NewGameAreYouSure_No };
MENUITEM* gMI_NewGameAreYouSureItems[] = { &gMI_NewGameAreYouSure_Yes, &gMI_NewGameAreYouSure_No };
MENU gMenu_NewGameAreYouSure = { "Are you sure you want to start a new game?", 1, _countof(gMI_NewGameAreYouSureItems), gMI_NewGameAreYouSureItems };
void DrawNewGameAreYouSure(void)
{
static uint64_t LocalFrameCounter;
static uint64_t LastFrameSeen = 0;
static int AlphaAdjust = -256;
// If global TotalFramesRendered is greater than LastFrameSeen,
// that means we have either just entered this gamestate for the first time,
// or we have left this gamestate previously and have just come back to it.
// For example we may have gone from the title screen, to the options screen,
// and then back to the title screen again. In that case, we want to reset all
// of the "local state," i.e., things that are local to this game state. Such
// as text animation, selected menu item, etc.
if (gPerformanceData.TotalFramesRendered > (LastFrameSeen + 1))
{
LocalFrameCounter = 0;
AlphaAdjust = -256;
gInputEnabled = false;
gMenu_NewGameAreYouSure.SelectedItem = 1;
}
memset(gBackBuffer.Memory, 0, GAME_DRAWING_AREA_MEMORY_SIZE);
#ifdef SMOOTH_FADES
// Here is a smoother fade in that looks nicer, but the original NES was not capable of such smooth gradients and fade
// effects. We will have to decide which we prefer later - looks better, or is more faithful to the original hardware?
if (AlphaAdjust < 0)
{
AlphaAdjust += 4;
}
#else
// Here is an easy, "chunky" fade-in from black in 4 steps, that sort of has a similar feel
// to the kind of fade-in you might have seen on the classic NES. AlphaAdjust starts at -256 and ends at 0.
switch (LocalFrameCounter)
{
case 15:
case 30:
case 45:
case 60:
{
AlphaAdjust += 64;
}
}
#endif
// It doesn't feel very nice to have to wait the full 60 frames for the fade-in to complete in order for
// input to be enabled again. We should enable it sooner so the kids with fast reflexes can work the menus quickly.
if (LocalFrameCounter == REENABLE_INPUT_AFTER_X_FRAMES_DELAY)
{
gInputEnabled = true;
}
BlitStringEx(
gMenu_NewGameAreYouSure.Name,
&g6x7Font,
(GAME_RES_WIDTH / 2) - ((uint16_t)(strlen(gMenu_NewGameAreYouSure.Name) * 6) / 2),
60,
255,
255,
255,
AlphaAdjust,
BLIT_FLAG_ALPHABLEND | BLIT_FLAG_TEXT_SHADOW);
#define PROGRESSWILLBELOSTSTRING "All unsaved progress will be lost!"
BlitStringEx(
PROGRESSWILLBELOSTSTRING,
&g6x7Font,
(GAME_RES_WIDTH / 2) - ((uint16_t)(strlen(PROGRESSWILLBELOSTSTRING) * 6) / 2),
75,
255,
255,
255,
AlphaAdjust,
BLIT_FLAG_ALPHABLEND | BLIT_FLAG_TEXT_SHADOW);
BlitStringEx(
gMenu_NewGameAreYouSure.Items[0]->Name,
&g6x7Font,
(GAME_RES_WIDTH / 2) - ((uint16_t)(strlen(gMenu_NewGameAreYouSure.Items[0]->Name) * 6) / 2),
100,
255,
255,
255,
AlphaAdjust,
BLIT_FLAG_ALPHABLEND | BLIT_FLAG_TEXT_SHADOW);
BlitStringEx(
gMenu_NewGameAreYouSure.Items[1]->Name,
&g6x7Font,
(GAME_RES_WIDTH / 2) - ((uint16_t)(strlen(gMenu_NewGameAreYouSure.Items[1]->Name) * 6) / 2),
115,
255,
255,
255,
AlphaAdjust,
BLIT_FLAG_ALPHABLEND | BLIT_FLAG_TEXT_SHADOW);
BlitStringEx(
"\xBB",
&g6x7Font,
gMenu_NewGameAreYouSure.Items[gMenu_NewGameAreYouSure.SelectedItem]->x - 6,
gMenu_NewGameAreYouSure.Items[gMenu_NewGameAreYouSure.SelectedItem]->y,
255,
255,
255,
AlphaAdjust,
BLIT_FLAG_ALPHABLEND | BLIT_FLAG_TEXT_SHADOW);
LocalFrameCounter++;
LastFrameSeen = gPerformanceData.TotalFramesRendered;
}
void PPI_NewGameAreYouSure(void)
{
if (gGameInput.DownKeyIsDown && !gGameInput.DownKeyWasDown)
{
PlayGameSound(&gSoundMenuNavigate);
if (gMenu_NewGameAreYouSure.SelectedItem < gMenu_NewGameAreYouSure.ItemCount - 1)
{
gMenu_NewGameAreYouSure.SelectedItem++;
}
else
{
gMenu_NewGameAreYouSure.SelectedItem = 0;
}
}
if (gGameInput.UpKeyIsDown && !gGameInput.UpKeyWasDown)
{
PlayGameSound(&gSoundMenuNavigate);
if (gMenu_NewGameAreYouSure.SelectedItem > 0)
{
gMenu_NewGameAreYouSure.SelectedItem--;
}
else
{
gMenu_NewGameAreYouSure.SelectedItem = gMenu_NewGameAreYouSure.ItemCount - 1;
}
}
if (gGameInput.ChooseKeyIsDown && !gGameInput.ChooseKeyWasDown)
{
gMenu_NewGameAreYouSure.Items[gMenu_NewGameAreYouSure.SelectedItem]->Action();
PlayGameSound(&gSoundMenuChoose);
}
}
void MenuItem_NewGameAreYouSure_Yes(void)
{
ASSERT(gCurrentGameState == GAMESTATE_NEWGAMEAREYOUSURE, "Invalid game state!");
ResetEverythingForNewGame();
}
void MenuItem_NewGameAreYouSure_No(void)
{
ASSERT(gCurrentGameState == GAMESTATE_NEWGAMEAREYOUSURE, "Invalid game state!");
gPreviousGameState = gCurrentGameState;
gCurrentGameState = GAMESTATE_TITLESCREEN;
LogMessageA(LL_INFO, "[%s] Transitioning from game state %d to %d. Player selected '%s' from '%s' menu.",
__FUNCTION__,
gPreviousGameState,
gCurrentGameState,
gMenu_NewGameAreYouSure.Items[gMenu_NewGameAreYouSure.SelectedItem]->Name,
gMenu_NewGameAreYouSure.Name);
}