|
@@ -140,10 +140,6 @@ bool Debuggers::OnUserCreate()
|
140
|
140
|
|
141
|
141
|
// Creating entities
|
142
|
142
|
|
143
|
|
- buttons.push_back(new Button(this, ScreenWidth() / 2 - 64, 100, 128, 16, "Start", STATE_GAME));
|
144
|
|
- buttons.push_back(new Button(this, ScreenWidth() / 2 - 64, 132, 128, 16, "Help", STATE_HELP));
|
145
|
|
- buttons.push_back(new Button(this, ScreenWidth() / 2 - 64, 164, 128, 16, "Quit", STATE_QUIT));
|
146
|
|
-
|
147
|
143
|
ResetGame();
|
148
|
144
|
SwitchState(STATE_MAIN_MENU);
|
149
|
145
|
olc::SOUND::PlaySample(bgMusic, true);
|
|
@@ -169,58 +165,76 @@ bool Debuggers::OnUserUpdate(float fElapsedTime)
|
169
|
165
|
debug = !debug;
|
170
|
166
|
}
|
171
|
167
|
#endif
|
|
168
|
+ bool result = false;
|
172
|
169
|
switch (state) {
|
173
|
170
|
case STATE_GAME:
|
174
|
171
|
case STATE_MAIN_MENU:
|
175
|
|
- return GamePlay(fElapsedTime);
|
|
172
|
+ result = GamePlay(fElapsedTime);
|
|
173
|
+ break;
|
176
|
174
|
case STATE_PAUSE_MENU:
|
177
|
|
- return PauseMenu(fElapsedTime);
|
|
175
|
+ result = PauseMenu(fElapsedTime);
|
|
176
|
+ break;
|
|
177
|
+ case STATE_HELP:
|
|
178
|
+ result = HelpMenu(fElapsedTime);
|
|
179
|
+ break;
|
178
|
180
|
case STATE_GAME_OVER:
|
179
|
|
- return GameOver(fElapsedTime);
|
|
181
|
+ result = GameOver(fElapsedTime);
|
|
182
|
+ break;
|
180
|
183
|
default:
|
181
|
|
- return false;
|
|
184
|
+ break;
|
182
|
185
|
}
|
|
186
|
+
|
|
187
|
+ for (auto& button : buttons) {
|
|
188
|
+ button->Draw();
|
|
189
|
+ if (button->Update()) {
|
|
190
|
+ break;
|
|
191
|
+ }
|
|
192
|
+ }
|
|
193
|
+ return result;
|
183
|
194
|
}
|
184
|
195
|
|
185
|
196
|
void Debuggers::DrawMenu()
|
186
|
197
|
{
|
187
|
|
- SetPixelMode(olc::Pixel::ALPHA);
|
188
|
|
- FillRect(0, 0, ScreenWidth(), ScreenHeight(), { 0, 0, 0, 160 });
|
189
|
|
- SetPixelMode(olc::Pixel::NORMAL);
|
190
|
|
-
|
191
|
|
- DrawString(ScreenWidth() / 2 - 144, 32, "DEBUGGERS", olc::YELLOW, 4);
|
192
|
|
- DrawString(ScreenWidth() - 128, 64, "by Pabloader");
|
193
|
|
- DrawString(ScreenWidth() - 17 * 8 - 2, ScreenHeight() - 10, "OLC Code Jam 2019");
|
|
198
|
+ DrawLogo();
|
194
|
199
|
|
195
|
200
|
std::string resumeText = state == STATE_PAUSE_MENU ? "Continue" : "Start";
|
196
|
201
|
if (buttons.size() > 0) {
|
197
|
202
|
buttons.front()->SetText(resumeText);
|
198
|
203
|
}
|
199
|
204
|
|
200
|
|
- // DrawString(ScreenWidth() / 2 - 144, 100, "SPACE to " + resumeText + " game");
|
201
|
|
- // DrawString(ScreenWidth() / 2 - 144, 116, "H to view help");
|
202
|
|
- // DrawString(ScreenWidth() / 2 - 144, 132, "X to quit");
|
203
|
|
-
|
204
|
|
- for (auto& button : buttons) {
|
205
|
|
- button->Update();
|
206
|
|
- button->Draw();
|
207
|
|
- }
|
208
|
|
-
|
209
|
|
- if (GetKey(olc::SPACE).bPressed || (GetKey(olc::ESCAPE).bPressed && state == STATE_PAUSE_MENU)) {
|
|
205
|
+ if (GetKey(olc::ESCAPE).bPressed && state == STATE_PAUSE_MENU) {
|
210
|
206
|
SwitchState(STATE_GAME);
|
211
|
207
|
}
|
|
208
|
+}
|
212
|
209
|
|
213
|
|
- if (GetKey(olc::H).bPressed) {
|
214
|
|
- SwitchState(STATE_HELP);
|
|
210
|
+void Debuggers::DrawSourceCode()
|
|
211
|
+{
|
|
212
|
+ int y = GameScreenHeight();
|
|
213
|
+ FillRect(0, y - 1, ScreenWidth(), ScreenHeight() - y + 1, olc::VERY_DARK_GREY);
|
|
214
|
+
|
|
215
|
+ for (auto& line : sourceCode) {
|
|
216
|
+ DrawString(1, y, line);
|
|
217
|
+ y += 10;
|
|
218
|
+ if (y >= ScreenHeight())
|
|
219
|
+ break;
|
215
|
220
|
}
|
|
221
|
+}
|
216
|
222
|
|
217
|
|
- if (GetKey(olc::X).bPressed) {
|
218
|
|
- SwitchState(STATE_QUIT);
|
219
|
|
- }
|
|
223
|
+void Debuggers::DrawLogo()
|
|
224
|
+{
|
|
225
|
+ SetPixelMode(olc::Pixel::ALPHA);
|
|
226
|
+ FillRect(0, 0, ScreenWidth(), ScreenHeight(), { 0, 0, 0, 128 });
|
|
227
|
+ SetPixelMode(olc::Pixel::NORMAL);
|
|
228
|
+
|
|
229
|
+ DrawString(ScreenWidth() / 2 - 144, 32, "DEBUGGERS", olc::YELLOW, 4);
|
|
230
|
+ DrawString(ScreenWidth() - 128, 64, "by Pabloader");
|
|
231
|
+ DrawString(ScreenWidth() - 17 * 8 - 2, ScreenHeight() - 10, "OLC Code Jam 2019");
|
220
|
232
|
}
|
221
|
233
|
|
222
|
234
|
void Debuggers::SwitchState(GameState newState)
|
223
|
235
|
{
|
|
236
|
+ prevState = state;
|
|
237
|
+ ClearButtons();
|
224
|
238
|
switch (newState) {
|
225
|
239
|
case STATE_GAME:
|
226
|
240
|
if (state == STATE_MAIN_MENU || state == STATE_GAME_OVER) {
|
|
@@ -231,6 +245,14 @@ void Debuggers::SwitchState(GameState newState)
|
231
|
245
|
case STATE_MAIN_MENU:
|
232
|
246
|
ResetGame();
|
233
|
247
|
SpawnProgrammer();
|
|
248
|
+ // fallthrough
|
|
249
|
+ case STATE_PAUSE_MENU:
|
|
250
|
+ buttons.push_back(new Button(this, ScreenWidth() / 2 - 64, 100, 128, 16, "Start", STATE_GAME));
|
|
251
|
+ buttons.push_back(new Button(this, ScreenWidth() / 2 - 64, 132, 128, 16, "Help", STATE_HELP));
|
|
252
|
+ buttons.push_back(new Button(this, ScreenWidth() / 2 - 64, 164, 128, 16, "Quit", STATE_QUIT));
|
|
253
|
+ break;
|
|
254
|
+ case STATE_HELP:
|
|
255
|
+ buttons.push_back(new Button(this, 16, 64, 64, 16, "Back", prevState));
|
234
|
256
|
break;
|
235
|
257
|
default:
|
236
|
258
|
break;
|
|
@@ -241,6 +263,7 @@ void Debuggers::SwitchState(GameState newState)
|
241
|
263
|
|
242
|
264
|
void Debuggers::ResetGame()
|
243
|
265
|
{
|
|
266
|
+ ClearButtons();
|
244
|
267
|
for (auto& i : programmers) {
|
245
|
268
|
delete i;
|
246
|
269
|
}
|
|
@@ -261,6 +284,14 @@ void Debuggers::ResetGame()
|
261
|
284
|
sourceCode = originalSourceCode;
|
262
|
285
|
}
|
263
|
286
|
|
|
287
|
+void Debuggers::ClearButtons()
|
|
288
|
+{
|
|
289
|
+ for (auto& i : buttons) {
|
|
290
|
+ delete i;
|
|
291
|
+ }
|
|
292
|
+ buttons.clear();
|
|
293
|
+}
|
|
294
|
+
|
264
|
295
|
void Debuggers::SpawnBug()
|
265
|
296
|
{
|
266
|
297
|
auto bug = CreateBug();
|