浏览代码

Help Screen

Pabloader 5 年前
父节点
当前提交
0c6453a9f0
共有 8 个文件被更改,包括 131 次插入58 次删除
  1. 2
    2
      TODO.md
  2. 1
    1
      include/button.h
  3. 5
    0
      include/debuggers.h
  4. 二进制
      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 查看文件

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

+ 1
- 1
include/button.h 查看文件

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

+ 5
- 0
include/debuggers.h 查看文件

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

二进制
res/enemies.png 查看文件


+ 1
- 1
src/bug.cpp 查看文件

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

+ 3
- 1
src/button.cpp 查看文件

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

+ 61
- 30
src/debuggers.cpp 查看文件

@@ -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();

+ 58
- 23
src/debuggers_states.cpp 查看文件

@@ -118,21 +118,12 @@ bool Debuggers::GamePlay(float fElapsedTime)
118 118
     }
119 119
 #endif
120 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 128
     if (state == STATE_MAIN_MENU) {
138 129
         DrawMenu();
@@ -162,16 +153,7 @@ bool Debuggers::PauseMenu(float fElapsedTime)
162 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 157
     DrawMenu();
176 158
 
177 159
     return true;
@@ -186,10 +168,63 @@ bool Debuggers::GameOver(float dt)
186 168
     DrawString(ScreenWidth() / 2 - 144, ScreenHeight() / 2 + 16, "Bugs catched: " + std::to_string(bugsCatched), olc::CYAN, 2);
187 169
     DrawString(ScreenWidth() / 2 - 144, ScreenHeight() / 2 + 34, "Press SPACE to continue");
188 170
 
171
+    // TODO main menu
172
+
189 173
     if (GetKey(olc::SPACE).bPressed) {
190 174
         SwitchState(STATE_MAIN_MENU);
191 175
     }
192 176
 
193 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
 }

正在加载...
取消
保存