Skip to content

Commit

Permalink
Pain SFX
Browse files Browse the repository at this point in the history
  • Loading branch information
nonk123 committed May 28, 2024
1 parent 047cb40 commit 9313f95
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
Binary file added assets/pain-1.wav
Binary file not shown.
Binary file added assets/pain-2.wav
Binary file not shown.
Binary file added assets/pain-3.wav
Binary file not shown.
9 changes: 8 additions & 1 deletion src/entities/pedo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

const constexpr float WIDTH = 3.0f, HEIGHT = 1.5f, VISUAL_HEIGHT = 10.0f;

const constexpr float FOOTSTEP_DELAY = 0.2f;
const constexpr float FOOTSTEP_DELAY = 0.2f, PAIN_DELAY = 1.4f;

const constexpr Color BLOOD{255, 0, 0, 255};
const constexpr float BLOOD_RADIUS = 2.5f, BLOOD_PROB = 0.32f;
Expand Down Expand Up @@ -55,6 +55,13 @@ void Pedo::update() {
}

if (dying) {
pain_countdown -= TICK_DELAY;

if (pain_countdown <= 0.0f) {
PlaySound(Sounds::random_pain());
pain_countdown = PAIN_DELAY;
}

die_countdown -= TICK_DELAY;

if (die_countdown <= 0.0f) {
Expand Down
2 changes: 1 addition & 1 deletion src/entities/pedo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class Pedo : public Entity {
public:
bool dying = false, safe = false;
float die_countdown = 0.0f, footstep_countdown = 0.0f;
float die_countdown = 0.0f, footstep_countdown = 0.0f, pain_countdown = 0.0f;

Pedo(float, float);

Expand Down
22 changes: 13 additions & 9 deletions src/sounds.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
#include <sstream>

#include "sounds.hpp"

void load_sounds() {
Sounds::pedo_die = LoadSound("assets/die.wav");
Sounds::crash = LoadSound("assets/fucked.wav");

for (std::size_t i = 0; i < Sounds::footstep.size(); i++) {
std::stringstream path_builder;
path_builder << "assets/footstep-";
path_builder << i + 1;
path_builder << ".wav";
Sounds::pain[0] = LoadSound("assets/pain-1.wav");
Sounds::pain[1] = LoadSound("assets/pain-2.wav");
Sounds::pain[2] = LoadSound("assets/pain-3.wav");

Sounds::footstep[i] = LoadSound(path_builder.str().c_str());
}
Sounds::footstep[0] = LoadSound("assets/footstep-1.wav");
Sounds::footstep[1] = LoadSound("assets/footstep-2.wav");
Sounds::footstep[2] = LoadSound("assets/footstep-3.wav");
Sounds::footstep[3] = LoadSound("assets/footstep-4.wav");
Sounds::footstep[4] = LoadSound("assets/footstep-5.wav");
Sounds::footstep[5] = LoadSound("assets/footstep-6.wav");
}

const Sound& Sounds::random_footstep() {
return footstep[GetRandomValue(0, footstep.size() - 1)];
}

const Sound& Sounds::random_pain() {
return pain[GetRandomValue(0, pain.size() - 1)];
}
2 changes: 2 additions & 0 deletions src/sounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

namespace Sounds {
inline std::array<Sound, 6> footstep;
inline std::array<Sound, 3> pain;
inline Sound pedo_die, crash;

const Sound& random_footstep();
const Sound& random_pain();
} // namespace Sounds

0 comments on commit 9313f95

Please sign in to comment.