summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-03-31 15:14:59 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-03-31 15:14:59 +0200
commitd87217dffc1582b8dbed10da62b3b4d3f7b511de (patch)
treebccdf9809bff291b405d7625c33dbbcd60411256 /src
parentaecfd089492b14a1b453f324a452946f5b20b043 (diff)
Footstep sounds (not finished).
Diffstat (limited to 'src')
-rw-r--r--src/audio.cpp11
-rw-r--r--src/common.hpp3
-rw-r--r--src/game/assets.cpp7
-rw-r--r--src/game/game.hpp4
-rw-r--r--src/game/units.cpp6
5 files changed, 27 insertions, 4 deletions
diff --git a/src/audio.cpp b/src/audio.cpp
index af6d24b..ff4fcd3 100644
--- a/src/audio.cpp
+++ b/src/audio.cpp
@@ -32,13 +32,19 @@ void clean_sounds(void)
void sound_t::load(const char *path)
{
printf("load %s\n", path);
- buffer.loadFromFile(path);
+
+ auto sound = sounds.emplace(sounds.end());
+ sound->loadFromFile(path);
}
void sound_t::play(void)
{
+ if (!sounds.size())
+ return;
+
auto sound = playing_sounds.emplace(playing_sounds.end());
- sound->setBuffer(buffer);
+ sound->setBuffer(sounds[rand() % sounds.size()]);
+ sound->setVolume(volume * 100.0f);
sound->play();
}
@@ -47,6 +53,7 @@ void ambient_t::load(const char *path)
printf("load %s\n", path);
sound.openFromFile(path);
sound.setLoop(true);
+ sound.setRelativeToListener(true);
ambient_sounds.push_back(this);
}
diff --git a/src/common.hpp b/src/common.hpp
index b4c16c6..2b9b9ca 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -432,9 +432,10 @@ namespace audio {
void update_ambience(bool playing);
class sound_t {
- sf::SoundBuffer buffer;
+ std::vector<sf::SoundBuffer> sounds;
public:
+ float volume = 1.0f;
void load(const char *path);
void play(void);
};
diff --git a/src/game/assets.cpp b/src/game/assets.cpp
index f14a060..f0dddbf 100644
--- a/src/game/assets.cpp
+++ b/src/game/assets.cpp
@@ -43,6 +43,13 @@ void load(void)
soldier.fire.load("assets/units/soldier/fire.ogg");
+ soldier.step_stone.load("assets/units/soldier/step_stone_1.ogg");
+ soldier.step_stone.load("assets/units/soldier/step_stone_2.ogg");
+ soldier.step_stone.load("assets/units/soldier/step_stone_3.ogg");
+ soldier.step_stone.load("assets/units/soldier/step_stone_4.ogg");
+ soldier.step_stone.load("assets/units/soldier/step_stone_5.ogg");
+ soldier.step_stone.volume = 0.4f;
+
spider.idle.load("assets/units/spider/idle", 2, 2, 2);
spider.walking.load("assets/units/spider/walking", 2, 2, 2);
spider.dead.load("assets/units/spider/dead_", 1);
diff --git a/src/game/game.hpp b/src/game/game.hpp
index 848ba92..bb2ce69 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -55,7 +55,7 @@ namespace game {
render::oriented_sprite_4M2_t legs_idle, legs_walking;
render::animated_texture_t dead;
- audio::sound_t fire;
+ audio::sound_t fire, step_stone, step_dirt;
} soldier_assets_t;
typedef struct {
@@ -194,6 +194,8 @@ namespace game {
bool blocked;
size_t attempts_left;
float next_attempt;
+
+ v2f_t last_step;
} move;
bool keep_moving(double speed);
diff --git a/src/game/units.cpp b/src/game/units.cpp
index f3d53d7..30cfdd5 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -171,6 +171,7 @@ bool unit_t::start_moving(v2f_t dst)
move.dst = dst;
move.path.clear();
+ move.last_step = x;
rep.cflags = move.cflags & ~(cmodel.cflags);
rep.bounds = cmodel.bounds;
@@ -454,6 +455,11 @@ void unit_soldier_t::on_think(void)
panic_turn = game->now + 0.3;
}
}
+
+ if (move.moving && (x - move.last_step).len() > 0.5f) {
+ move.last_step = x;
+ assets::soldier.step_stone.play();
+ }
}
void unit_soldier_t::on_death(void)