Переглянути джерело

Add bonus sound, tweak some bug spawn parameters

Pabloader 4 роки тому
джерело
коміт
993db0f6c8
6 змінених файлів з 31 додано та 18 видалено
  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 Переглянути файл

103
     int bugCatchSample;
103
     int bugCatchSample;
104
     int hoverSample;
104
     int hoverSample;
105
     int clickSample;
105
     int clickSample;
106
+    int bonusSample;
106
 
107
 
107
     const int gravity = 20;
108
     const int gravity = 20;
108
 #ifdef _DEBUG
109
 #ifdef _DEBUG


+ 7
- 0
src/debuggers.cpp Переглянути файл

91
         return false;
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
     // Load background
101
     // Load background
95
 
102
 
96
     fileName = "res/bg.pgs";
103
     fileName = "res/bg.pgs";

+ 14
- 12
src/debuggers_states.cpp Переглянути файл

12
     DrawSprite(0, 0, &backgroundSprite);
12
     DrawSprite(0, 0, &backgroundSprite);
13
 
13
 
14
     uint32_t bugsSize = bugs.size();
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
     Programmer* player = programmers.front();
17
     Programmer* player = programmers.front();
18
 
18
 
27
                         bugsCatchedByPlayer++;
27
                         bugsCatchedByPlayer++;
28
                     }
28
                     }
29
                     SpawnBugParticles(bug);
29
                     SpawnBugParticles(bug);
30
-                    bug->Kill();
31
                     if (state == STATE_GAME)
30
                     if (state == STATE_GAME)
32
                         olc::SOUND::PlaySample(bugCatchSample);
31
                         olc::SOUND::PlaySample(bugCatchSample);
32
+
33
+                    bug->Kill();
33
                     SpawnBug();
34
                     SpawnBug();
34
                 }
35
                 }
35
             }
36
             }
36
         } else if (bug->IsAlive()) {
37
         } else if (bug->IsAlive()) {
37
             bugsMissed++;
38
             bugsMissed++;
39
+            bug->Kill();
38
             SpawnBug();
40
             SpawnBug();
39
             if (state == STATE_GAME) {
41
             if (state == STATE_GAME) {
40
                 sourceCode.erase(sourceCode.begin());
42
                 sourceCode.erase(sourceCode.begin());
59
             if (player->Collides(bonus)) {
61
             if (player->Collides(bonus)) {
60
                 auto type = bonus->GetType();
62
                 auto type = bonus->GetType();
61
                 if (type == BONUS_DOCUMENTATION) {
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
                 } else {
73
                 } else {
72
                     bonusesCatched[type]++;
74
                     bonusesCatched[type]++;
73
                 }
75
                 }
74
                 bonus->Kill();
76
                 bonus->Kill();
75
-                // TODO play pickup sound
77
+                olc::SOUND::PlaySample(bonusSample);
76
             }
78
             }
77
         } else {
79
         } else {
78
             bonus->Kill();
80
             bonus->Kill();
99
         SpawnProgrammer();
101
         SpawnProgrammer();
100
     }
102
     }
101
 
103
 
102
-    if (bugsCatched > 12 * bugsSize) {
104
+    if (bugsCatched > 14 * bugsSize) {
103
         SpawnBug();
105
         SpawnBug();
104
     }
106
     }
105
 
107
 
106
-    if (GetRandom<float>() < 0.01 * fElapsedTime) {
108
+    if (GetRandom<float>() < 0.03 * fElapsedTime) {
107
         SpawnBonus();
109
         SpawnBonus();
108
     }
110
     }
109
 
111
 

+ 8
- 6
src/entity.cpp Переглянути файл

32
 
32
 
33
 void Entity::Draw()
33
 void Entity::Draw()
34
 {
34
 {
35
+    if (IsInScreen()) {
35
 #ifdef _DEBUG
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
 #endif
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
 bool Entity::IsActive()
47
 bool Entity::IsActive()

+ 1
- 0
src/programmer.cpp Переглянути файл

145
         olc::GFX2D::DrawPartialSprite(&game->playerSprite, tile.x * size.x + xOff, size.y + tile.y * size.y, size.x - xOff, size.y, transform, true);
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
     game->SetPixelMode(olc::Pixel::NORMAL);
147
     game->SetPixelMode(olc::Pixel::NORMAL);
148
+    
148
 #ifdef _DEBUG
149
 #ifdef _DEBUG
149
     if (game->debug) {
150
     if (game->debug) {
150
         game->DrawRect(pos.x - size.x / 2, pos.y - size.y / 2, size.x, size.y, DEBUG_COLOR);
151
         game->DrawRect(pos.x - size.x / 2, pos.y - size.y / 2, size.x, size.y, DEBUG_COLOR);

Loading…
Відмінити
Зберегти