Browse Source

Catching bonuses

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

+ 7
- 3
include/debuggers.h View File

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

+ 6
- 1
src/bonus.cpp View File

8
     : Entity(game, &game->bonusesSprite)
8
     : Entity(game, &game->bonusesSprite)
9
 {
9
 {
10
     tileCols = 1;
10
     tileCols = 1;
11
-    tileRows = 1;
11
+    tileRows = 2;
12
 #ifdef _DEBUG
12
 #ifdef _DEBUG
13
     DEBUG_COLOR = olc::YELLOW;
13
     DEBUG_COLOR = olc::YELLOW;
14
 #endif
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
             bonus->Update(fElapsedTime);
146
             bonus->Update(fElapsedTime);
147
             bonus->Draw();
147
             bonus->Draw();
148
             if (player->Collides(bonus)) {
148
             if (player->Collides(bonus)) {
149
-                // TODO add to inventory
149
+                bonusesCatched[bonus->GetType()]++;
150
                 bonus->Kill();
150
                 bonus->Kill();
151
             }
151
             }
152
         }
152
         }
176
     DrawString(1, 37, "Bugs: " + std::to_string(bugs.size()));
176
     DrawString(1, 37, "Bugs: " + std::to_string(bugs.size()));
177
     DrawString(1, 46, "Progs: " + std::to_string(programmers.size()));
177
     DrawString(1, 46, "Progs: " + std::to_string(programmers.size()));
178
     DrawString(1, 55, "Bonuses: " + std::to_string(bonuses.size()));
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
     if (GetKey(olc::B).bPressed) {
182
     if (GetKey(olc::B).bPressed) {
180
         SpawnBug();
183
         SpawnBug();
181
     }
184
     }

Loading…
Cancel
Save