Browse Source

Help Screen

Pabloader 5 years ago
parent
commit
0c6453a9f0
8 changed files with 131 additions and 58 deletions
  1. 2
    2
      TODO.md
  2. 1
    1
      include/button.h
  3. 5
    0
      include/debuggers.h
  4. BIN
      res/enemies.png
  5. 1
    1
      src/bug.cpp
  6. 3
    1
      src/button.cpp
  7. 61
    30
      src/debuggers.cpp
  8. 58
    23
      src/debuggers_states.cpp

+ 2
- 2
TODO.md View File

2
 
2
 
3
  - [x] Main menu
3
  - [x] Main menu
4
  - [x] Pause (ESC) menu
4
  - [x] Pause (ESC) menu
5
-   - [ ] Mouse menu
6
- - [ ] Help screen
5
+   - [x] Mouse menu
6
+ - [x] Help screen
7
 
7
 
8
  - [ ] ~~Bugs only catchable by 2 programmers~~
8
  - [ ] ~~Bugs only catchable by 2 programmers~~
9
  - [ ] ~~Bugs only catchable with debugger~~
9
  - [ ] ~~Bugs only catchable with debugger~~

+ 1
- 1
include/button.h View File

13
 public:
13
 public:
14
     Button(Debuggers* game, int32_t x, int32_t y, int32_t w, int32_t h, std::string txt, GameState state);
14
     Button(Debuggers* game, int32_t x, int32_t y, int32_t w, int32_t h, std::string txt, GameState state);
15
     void Draw();
15
     void Draw();
16
-    void Update();
16
+    bool Update();
17
     void SetText(std::string txt) { text = txt; }
17
     void SetText(std::string txt) { text = txt; }
18
 
18
 
19
 private:
19
 private:

+ 5
- 0
include/debuggers.h View File

38
     std::list<std::string> sourceCode;
38
     std::list<std::string> sourceCode;
39
 
39
 
40
     GameState state = STATE_MAIN_MENU;
40
     GameState state = STATE_MAIN_MENU;
41
+    GameState prevState;
42
+    float helpRotation = 0;
41
 
43
 
42
     std::mt19937 generator;
44
     std::mt19937 generator;
43
 
45
 
61
 
63
 
62
 private:
64
 private:
63
     void ResetGame();
65
     void ResetGame();
66
+    void ClearButtons();
64
     void DrawMenu();
67
     void DrawMenu();
68
+    void DrawSourceCode();
69
+    void DrawLogo();
65
 
70
 
66
     void SpawnPlayer();
71
     void SpawnPlayer();
67
     void SpawnProgrammer();
72
     void SpawnProgrammer();

BIN
res/enemies.png View File


+ 1
- 1
src/bug.cpp View File

7
 Bug::Bug(Debuggers* game)
7
 Bug::Bug(Debuggers* game)
8
     : Entity(game, &game->enemiesSprite)
8
     : Entity(game, &game->enemiesSprite)
9
 {
9
 {
10
-    tileDim.x = 1;
10
+    tileDim.x = 2;
11
 #ifdef _DEBUG
11
 #ifdef _DEBUG
12
     DEBUG_COLOR = olc::RED;
12
     DEBUG_COLOR = olc::RED;
13
 #endif
13
 #endif

+ 3
- 1
src/button.cpp View File

11
 {
11
 {
12
 }
12
 }
13
 
13
 
14
-void Button::Update()
14
+bool Button::Update()
15
 {
15
 {
16
     auto x = game->GetMouseX();
16
     auto x = game->GetMouseX();
17
     auto y = game->GetMouseY();
17
     auto y = game->GetMouseY();
23
     if (hover && game->GetMouse(0).bPressed) {
23
     if (hover && game->GetMouse(0).bPressed) {
24
         olc::SOUND::PlaySample(game->clickSample);
24
         olc::SOUND::PlaySample(game->clickSample);
25
         game->SwitchState(state);
25
         game->SwitchState(state);
26
+        return true;
26
     }
27
     }
28
+    return false;
27
 }
29
 }
28
 
30
 
29
 void Button::Draw()
31
 void Button::Draw()

+ 61
- 30
src/debuggers.cpp View File

140
 
140
 
141
     // Creating entities
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
     ResetGame();
143
     ResetGame();
148
     SwitchState(STATE_MAIN_MENU);
144
     SwitchState(STATE_MAIN_MENU);
149
     olc::SOUND::PlaySample(bgMusic, true);
145
     olc::SOUND::PlaySample(bgMusic, true);
169
         debug = !debug;
165
         debug = !debug;
170
     }
166
     }
171
 #endif
167
 #endif
168
+    bool result = false;
172
     switch (state) {
169
     switch (state) {
173
     case STATE_GAME:
170
     case STATE_GAME:
174
     case STATE_MAIN_MENU:
171
     case STATE_MAIN_MENU:
175
-        return GamePlay(fElapsedTime);
172
+        result = GamePlay(fElapsedTime);
173
+        break;
176
     case STATE_PAUSE_MENU:
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
     case STATE_GAME_OVER:
180
     case STATE_GAME_OVER:
179
-        return GameOver(fElapsedTime);
181
+        result = GameOver(fElapsedTime);
182
+        break;
180
     default:
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
 void Debuggers::DrawMenu()
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
     std::string resumeText = state == STATE_PAUSE_MENU ? "Continue" : "Start";
200
     std::string resumeText = state == STATE_PAUSE_MENU ? "Continue" : "Start";
196
     if (buttons.size() > 0) {
201
     if (buttons.size() > 0) {
197
         buttons.front()->SetText(resumeText);
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
         SwitchState(STATE_GAME);
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
 void Debuggers::SwitchState(GameState newState)
234
 void Debuggers::SwitchState(GameState newState)
223
 {
235
 {
236
+    prevState = state;
237
+    ClearButtons();
224
     switch (newState) {
238
     switch (newState) {
225
     case STATE_GAME:
239
     case STATE_GAME:
226
         if (state == STATE_MAIN_MENU || state == STATE_GAME_OVER) {
240
         if (state == STATE_MAIN_MENU || state == STATE_GAME_OVER) {
231
     case STATE_MAIN_MENU:
245
     case STATE_MAIN_MENU:
232
         ResetGame();
246
         ResetGame();
233
         SpawnProgrammer();
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
         break;
256
         break;
235
     default:
257
     default:
236
         break;
258
         break;
241
 
263
 
242
 void Debuggers::ResetGame()
264
 void Debuggers::ResetGame()
243
 {
265
 {
266
+    ClearButtons();
244
     for (auto& i : programmers) {
267
     for (auto& i : programmers) {
245
         delete i;
268
         delete i;
246
     }
269
     }
261
     sourceCode = originalSourceCode;
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
 void Debuggers::SpawnBug()
295
 void Debuggers::SpawnBug()
265
 {
296
 {
266
     auto bug = CreateBug();
297
     auto bug = CreateBug();

+ 58
- 23
src/debuggers_states.cpp View File

118
     }
118
     }
119
 #endif
119
 #endif
120
     if (state == STATE_GAME) {
120
     if (state == STATE_GAME) {
121
-        DrawString(1, 1, "A,S,D - move; SPACE - jump", olc::CYAN);
122
-        DrawString(1, 10, "Don't let the bugs destroy your code!", olc::YELLOW);
123
-        DrawString(1, 19, "Bugs catched: " + std::to_string(bugsCatched));
124
-        DrawString(1, 28, "Bugs missed: " + std::to_string(bugsMissed));
121
+        DrawString(1, 1, "Don't let the bugs destroy your code!", olc::YELLOW);
122
+        DrawString(1, 10, "Bugs catched: " + std::to_string(bugsCatched));
123
+        DrawString(1, 19, "Bugs missed: " + std::to_string(bugsMissed));
125
     }
124
     }
126
 
125
 
127
-    int y = GameScreenHeight();
128
-    FillRect(0, y - 1, ScreenWidth(), ScreenHeight() - y + 1, olc::VERY_DARK_GREY);
129
-
130
-    for (auto& line : sourceCode) {
131
-        DrawString(1, y, line);
132
-        y += 10;
133
-        if (y >= ScreenHeight())
134
-            break;
135
-    }
126
+    DrawSourceCode();
136
 
127
 
137
     if (state == STATE_MAIN_MENU) {
128
     if (state == STATE_MAIN_MENU) {
138
         DrawMenu();
129
         DrawMenu();
162
         programmer->Draw();
153
         programmer->Draw();
163
     }
154
     }
164
 
155
 
165
-    int y = GameScreenHeight();
166
-    FillRect(0, y - 1, ScreenWidth(), ScreenHeight() - y + 1, olc::VERY_DARK_GREY);
167
-
168
-    for (auto& line : sourceCode) {
169
-        DrawString(1, y, line);
170
-        y += 10;
171
-        if (y >= ScreenHeight())
172
-            break;
173
-    }
174
-
156
+    DrawSourceCode();
175
     DrawMenu();
157
     DrawMenu();
176
 
158
 
177
     return true;
159
     return true;
186
     DrawString(ScreenWidth() / 2 - 144, ScreenHeight() / 2 + 16, "Bugs catched: " + std::to_string(bugsCatched), olc::CYAN, 2);
168
     DrawString(ScreenWidth() / 2 - 144, ScreenHeight() / 2 + 16, "Bugs catched: " + std::to_string(bugsCatched), olc::CYAN, 2);
187
     DrawString(ScreenWidth() / 2 - 144, ScreenHeight() / 2 + 34, "Press SPACE to continue");
169
     DrawString(ScreenWidth() / 2 - 144, ScreenHeight() / 2 + 34, "Press SPACE to continue");
188
 
170
 
171
+    // TODO main menu
172
+
189
     if (GetKey(olc::SPACE).bPressed) {
173
     if (GetKey(olc::SPACE).bPressed) {
190
         SwitchState(STATE_MAIN_MENU);
174
         SwitchState(STATE_MAIN_MENU);
191
     }
175
     }
192
 
176
 
193
     return true;
177
     return true;
194
 }
178
 }
179
+
180
+bool Debuggers::HelpMenu(float dt)
181
+{
182
+    DrawSprite(0, 0, &backgroundSprite);
183
+    DrawSourceCode();
184
+    DrawLogo();
185
+
186
+    auto y = 96;
187
+
188
+    DrawString(16, y, "A,S,D - move left/down/right");
189
+    y += 9;
190
+    DrawString(16, y, "SPACE - jump");
191
+    y += 9;
192
+    DrawString(16, y, "Bugs, you must destroy them: ");
193
+    y += 9;
194
+
195
+    helpRotation += dt;
196
+    auto w = enemiesSprite.width / 4;
197
+    auto h = enemiesSprite.height / 4;
198
+
199
+    y += h;
200
+
201
+    olc::GFX2D::Transform2D transform;
202
+    transform.Scale(2, 2);
203
+    transform.Rotate(helpRotation);
204
+    transform.Translate(16 + w / 2, y);
205
+
206
+    SetPixelMode(olc::Pixel::MASK);
207
+    for (auto i = 0; i < 2; i++) {
208
+        for (auto j = 0; j < 4; j++) {
209
+            olc::GFX2D::DrawPartialSprite(&enemiesSprite, i * w, j * h, w, h, transform, true);
210
+            transform.Translate(w * 2, 0);
211
+        }
212
+    }
213
+    y += h;
214
+    w = bonusesSprite.width / 4;
215
+    h = bonusesSprite.height / 4;
216
+
217
+    DrawString(16, y, "RTFM removes 10% bugs: ");
218
+    y += 9 + h / 2;
219
+
220
+    DrawPartialSprite(16 + w / 2, y, &bonusesSprite, 0, 0, w, h, 1, true);
221
+
222
+    SetPixelMode(olc::Pixel::NORMAL);
223
+
224
+    if (GetKey(olc::ESCAPE).bPressed) {
225
+        SwitchState(prevState);
226
+    }
227
+
228
+    return true;
229
+}
195
 }
230
 }

Loading…
Cancel
Save