Browse Source

Add bonus sound, tweak some bug spawn parameters

Pabloader 5 years ago
parent
commit
993db0f6c8
6 changed files with 31 additions and 18 deletions
  1. 1
    0
      include/debuggers.h
  2. BIN
      res/bonus.wav
  3. 7
    0
      src/debuggers.cpp
  4. 14
    12
      src/debuggers_states.cpp
  5. 8
    6
      src/entity.cpp
  6. 1
    0
      src/programmer.cpp

+ 1
- 0
include/debuggers.h View File

@@ -103,6 +103,7 @@ public:
103 103
     int bugCatchSample;
104 104
     int hoverSample;
105 105
     int clickSample;
106
+    int bonusSample;
106 107
 
107 108
     const int gravity = 20;
108 109
 #ifdef _DEBUG

BIN
res/bonus.wav View File


+ 7
- 0
src/debuggers.cpp View File

@@ -91,6 +91,13 @@ bool Debuggers::OnUserCreate()
91 91
         return false;
92 92
     }
93 93
 
94
+    fileName = "res/bonus.wav";
95
+    bonusSample = olc::SOUND::LoadAudioSample(fileName, &pack);
96
+    if (bonusSample < 0) {
97
+        std::cerr << "[Load bonus] File " << fileName << " is not found" << std::endl;
98
+        return false;
99
+    }
100
+
94 101
     // Load background
95 102
 
96 103
     fileName = "res/bg.pgs";

+ 14
- 12
src/debuggers_states.cpp View File

@@ -12,7 +12,7 @@ bool Debuggers::GamePlay(float fElapsedTime)
12 12
     DrawSprite(0, 0, &backgroundSprite);
13 13
 
14 14
     uint32_t bugsSize = bugs.size();
15
-    auto aliveBugs = std::count_if(bugs.begin(), bugs.end(), [](Bug* bug) { return bug->IsActive() && bug->IsAlive(); });
15
+    int aliveBugs = std::count_if(bugs.begin(), bugs.end(), [](Bug* bug) { return bug->IsActive() && bug->IsAlive(); });
16 16
 
17 17
     Programmer* player = programmers.front();
18 18
 
@@ -27,14 +27,16 @@ bool Debuggers::GamePlay(float fElapsedTime)
27 27
                         bugsCatchedByPlayer++;
28 28
                     }
29 29
                     SpawnBugParticles(bug);
30
-                    bug->Kill();
31 30
                     if (state == STATE_GAME)
32 31
                         olc::SOUND::PlaySample(bugCatchSample);
32
+
33
+                    bug->Kill();
33 34
                     SpawnBug();
34 35
                 }
35 36
             }
36 37
         } else if (bug->IsAlive()) {
37 38
             bugsMissed++;
39
+            bug->Kill();
38 40
             SpawnBug();
39 41
             if (state == STATE_GAME) {
40 42
                 sourceCode.erase(sourceCode.begin());
@@ -59,20 +61,20 @@ bool Debuggers::GamePlay(float fElapsedTime)
59 61
             if (player->Collides(bonus)) {
60 62
                 auto type = bonus->GetType();
61 63
                 if (type == BONUS_DOCUMENTATION) {
62
-                    if (aliveBugs > 1) {
63
-                        for (auto& bug : bugs) {
64
-                            if (bug->IsAlive() && bug->IsActive()) {
65
-                                SpawnBugParticles(bug);
66
-                                bug->Kill();
67
-                                break;
68
-                            }
64
+                    auto count = std::max(aliveBugs / 10, 1);
65
+                    for (auto& bug : bugs) {
66
+                        SpawnBugParticles(bug);
67
+                        bug->Kill();
68
+                        count--;
69
+                        if (count <= 0) {
70
+                            break;
69 71
                         }
70 72
                     }
71 73
                 } else {
72 74
                     bonusesCatched[type]++;
73 75
                 }
74 76
                 bonus->Kill();
75
-                // TODO play pickup sound
77
+                olc::SOUND::PlaySample(bonusSample);
76 78
             }
77 79
         } else {
78 80
             bonus->Kill();
@@ -99,11 +101,11 @@ bool Debuggers::GamePlay(float fElapsedTime)
99 101
         SpawnProgrammer();
100 102
     }
101 103
 
102
-    if (bugsCatched > 12 * bugsSize) {
104
+    if (bugsCatched > 14 * bugsSize) {
103 105
         SpawnBug();
104 106
     }
105 107
 
106
-    if (GetRandom<float>() < 0.01 * fElapsedTime) {
108
+    if (GetRandom<float>() < 0.03 * fElapsedTime) {
107 109
         SpawnBonus();
108 110
     }
109 111
 

+ 8
- 6
src/entity.cpp View File

@@ -32,14 +32,16 @@ bool Entity::Collides(Entity* entity)
32 32
 
33 33
 void Entity::Draw()
34 34
 {
35
+    if (IsInScreen()) {
35 36
 #ifdef _DEBUG
36
-    if (game->debug) {
37
-        game->DrawRect(pos.x - size.x / 2, pos.y - size.y / 2, size.x, size.y, DEBUG_COLOR);
38
-    }
37
+        if (game->debug) {
38
+            game->DrawRect(pos.x - size.x / 2, pos.y - size.y / 2, size.x, size.y, DEBUG_COLOR);
39
+        }
39 40
 #endif
40
-    game->SetPixelMode(olc::Pixel::MASK);
41
-    olc::GFX2D::DrawPartialSprite(sprite, tile.x * size.x, tile.y * size.y, size.x, size.y, transform, true);
42
-    game->SetPixelMode(olc::Pixel::NORMAL);
41
+        game->SetPixelMode(olc::Pixel::MASK);
42
+        olc::GFX2D::DrawPartialSprite(sprite, tile.x * size.x, tile.y * size.y, size.x, size.y, transform, true);
43
+        game->SetPixelMode(olc::Pixel::NORMAL);
44
+    }
43 45
 }
44 46
 
45 47
 bool Entity::IsActive()

+ 1
- 0
src/programmer.cpp View File

@@ -145,6 +145,7 @@ void Programmer::Draw()
145 145
         olc::GFX2D::DrawPartialSprite(&game->playerSprite, tile.x * size.x + xOff, size.y + tile.y * size.y, size.x - xOff, size.y, transform, true);
146 146
     }
147 147
     game->SetPixelMode(olc::Pixel::NORMAL);
148
+    
148 149
 #ifdef _DEBUG
149 150
     if (game->debug) {
150 151
         game->DrawRect(pos.x - size.x / 2, pos.y - size.y / 2, size.x, size.y, DEBUG_COLOR);

Loading…
Cancel
Save