Browse Source

Catching bonuses

Pabloader 4 years ago
parent
commit
e4ec2260b5
4 changed files with 24 additions and 5 deletions
  1. 7
    0
      include/bonus.h
  2. 7
    3
      include/debuggers.h
  3. 6
    1
      src/bonus.cpp
  4. 4
    1
      src/debuggers.cpp

+ 7
- 0
include/bonus.h View File

@@ -4,9 +4,16 @@
4 4
 #include "entity.h"
5 5
 
6 6
 namespace pabloader {
7
+
8
+enum BonusType {
9
+    BONUS_DEBUGGER = 0,
10
+    BONUS_UNIT_TEST = 1
11
+};
12
+
7 13
 class Bonus : public Entity {
8 14
 public:
9 15
     Bonus(Debuggers* game);
16
+    BonusType GetType();
10 17
 };
11 18
 }
12 19
 

+ 7
- 3
include/debuggers.h View File

@@ -9,10 +9,11 @@
9 9
 #include "player.h"
10 10
 #include "programmer.h"
11 11
 
12
+#include <chrono>
13
+#include <map>
14
+#include <random>
12 15
 #include <string>
13 16
 #include <vector>
14
-#include <random>
15
-#include <chrono>
16 17
 
17 18
 namespace pabloader {
18 19
 class Debuggers : public olc::PixelGameEngine {
@@ -20,6 +21,8 @@ private:
20 21
     std::vector<Programmer*> programmers;
21 22
     std::vector<Bonus*> bonuses;
22 23
 
24
+    std::map<BonusType, uint32_t> bonusesCatched;
25
+
23 26
     uint32_t bugsCatched = 0;
24 27
     uint32_t bugsMissed = 0;
25 28
 
@@ -30,7 +33,8 @@ private:
30 33
     std::mt19937 generator;
31 34
 
32 35
 public:
33
-    Debuggers(): generator(rd())
36
+    Debuggers()
37
+        : generator(rd())
34 38
     {
35 39
         sAppName = "Debuggers";
36 40
     }

+ 6
- 1
src/bonus.cpp View File

@@ -8,9 +8,14 @@ Bonus::Bonus(Debuggers* game)
8 8
     : Entity(game, &game->bonusesSprite)
9 9
 {
10 10
     tileCols = 1;
11
-    tileRows = 1;
11
+    tileRows = 2;
12 12
 #ifdef _DEBUG
13 13
     DEBUG_COLOR = olc::YELLOW;
14 14
 #endif
15 15
 }
16
+
17
+BonusType Bonus::GetType()
18
+{
19
+    return static_cast<BonusType>(tileX * 4 + tileY);
20
+}
16 21
 }

+ 4
- 1
src/debuggers.cpp View File

@@ -146,7 +146,7 @@ bool Debuggers::OnUserUpdate(float fElapsedTime)
146 146
             bonus->Update(fElapsedTime);
147 147
             bonus->Draw();
148 148
             if (player->Collides(bonus)) {
149
-                // TODO add to inventory
149
+                bonusesCatched[bonus->GetType()]++;
150 150
                 bonus->Kill();
151 151
             }
152 152
         }
@@ -176,6 +176,9 @@ bool Debuggers::OnUserUpdate(float fElapsedTime)
176 176
     DrawString(1, 37, "Bugs: " + std::to_string(bugs.size()));
177 177
     DrawString(1, 46, "Progs: " + std::to_string(programmers.size()));
178 178
     DrawString(1, 55, "Bonuses: " + std::to_string(bonuses.size()));
179
+    DrawString(1, 64, "DBG: " + std::to_string(bonusesCatched[BONUS_DEBUGGER]));
180
+    DrawString(1, 73, "UTS: " + std::to_string(bonusesCatched[BONUS_UNIT_TEST]));
181
+    
179 182
     if (GetKey(olc::B).bPressed) {
180 183
         SpawnBug();
181 184
     }

Loading…
Cancel
Save