Commit 56b1ffb9 authored by Florian Oetke's avatar Florian Oetke
Browse files

added sound effects

parent 047dc7aa
......@@ -3,6 +3,7 @@
#include "beat_system.hpp"
#include "combat_system.hpp"
#include "movement_comp.hpp"
#include "player_comp.hpp"
#include "rigid_body_comp.hpp"
#include "../level/level_system.hpp"
......@@ -63,12 +64,20 @@ namespace phase_shifter::gameplay {
if(aim_len < 0.0001f) {
// TODO: attack
move.attack = true;
if(entity.has<Player_comp>()) {
_bus.send<Play_sound_msg>("attack"_strid);
}
} else {
// start movement
move.step_time_left = beat.avg_beat_time * move.step_time_percentage;
move.step_time = move.step_time_left;
move.last_step =
(aim_len > 1.f ? move.aim / aim_len : move.aim) * move.distance_per_step;
if(entity.has<Player_comp>()) {
_bus.send<Play_sound_msg>("dash"_strid);
}
}
} else {
......
#pragma once
#include <mirrage/ecs/types.hpp>
#include <mirrage/utils/str_id.hpp>
#include <glm/vec3.hpp>
......@@ -20,4 +21,8 @@ namespace phase_shifter {
glm::vec3 attack_direction;
};
struct Play_sound_msg {
mirrage::util::Str_id id;
};
} // namespace phase_shifter
#include "meta_system.hpp"
#include "audio/audio_asset.hpp"
#include "audio/sound_manager.hpp"
#include "game_engine.hpp"
#include "gameplay/beat_system.hpp"
#include "gameplay/camera_system.hpp"
#include "gameplay/combat_system.hpp"
#include "gameplay/dash_system.hpp"
#include "gameplay/stationary_attack_system.hpp"
#include "gameplay/enemy_system.hpp"
#include "gameplay/killable_comp.hpp"
#include "gameplay/movement_system.hpp"
#include "gameplay/stationary_attack_system.hpp"
#include "helper/attachment_system.hpp"
#include "input/input_system.hpp"
#include "level/level_system.hpp"
......@@ -34,6 +35,7 @@ namespace phase_shifter {
, _audio()
, _renderer(engine.renderer_factory().create_renderer(_entities, engine.render_pass_mask()))
, _model_loading(std::make_unique<renderer::Loading_system>(_entities, engine.assets()))
, _sound_manager(std::make_unique<audio::Sound_manager>(_audio, engine.bus(), engine.assets()))
, _beat_system(std::make_unique<gameplay::Beat_system>(engine.bus(), engine.assets()))
, _level_system(std::make_unique<level::Level_system>(_entities, engine.assets()))
, _movement_system(std::make_unique<gameplay::Movement_system>(
......@@ -45,9 +47,12 @@ namespace phase_shifter {
, _camera_system(std::make_unique<gameplay::Camera_system>(_entities))
, _enemy_system(std::make_unique<gameplay::Enemy_system>(_entities))
, _dash_system(std::make_unique<gameplay::Dash_system>(engine.bus(), _entities))
, _stationary_attack_system(std::make_unique<gameplay::Stationary_attack_system>(engine.bus(), _entities))
, _stationary_attack_system(
std::make_unique<gameplay::Stationary_attack_system>(engine.bus(), _entities))
, _effect_system(std::make_unique<ui::Effect_system>(engine.bus(), _entities))
{
_sound_manager->load_effects_file("cfg:sound_effects"_aid);
_entities.register_component_type<ecs::components::Transform_comp>();
//auto s = _renderer->settings();
......@@ -119,6 +124,7 @@ namespace phase_shifter {
_model_loading->update(dt);
_renderer->update(dt * _beat_system->graphic_time_scale());
_sound_manager->update(dt);
}
void Meta_system::draw()
{
......@@ -127,8 +133,16 @@ namespace phase_shifter {
}
void Meta_system::pause() { _input_system->disable(); }
void Meta_system::resume() { _input_system->enable(); }
void Meta_system::pause()
{
_input_system->disable();
_sound_manager->pause();
}
void Meta_system::resume()
{
_input_system->enable();
_sound_manager->resume();
}
void Meta_system::shrink_to_fit() { _renderer->shrink_to_fit(); }
......
......@@ -19,6 +19,9 @@ namespace mirrage {
namespace phase_shifter {
class Game_engine;
namespace audio {
class Sound_manager;
}
namespace gameplay {
class Beat_system;
class Movement_system;
......@@ -64,19 +67,20 @@ namespace phase_shifter {
eam::audio _audio;
std::unique_ptr<mirrage::renderer::Deferred_renderer> _renderer;
std::unique_ptr<mirrage::renderer::Loading_system> _model_loading;
std::unique_ptr<audio::Sound_manager> _sound_manager;
std::unique_ptr<gameplay::Beat_system> _beat_system;
std::unique_ptr<level::Level_system> _level_system;
std::unique_ptr<gameplay::Movement_system> _movement_system;
std::unique_ptr<input::Input_system> _input_system;
std::unique_ptr<gameplay::Combat_system> _combat_system;
std::unique_ptr<helper::Attachment_system> _attachment_system;
std::unique_ptr<ui::Hud_system> _hud_system;
std::unique_ptr<gameplay::Camera_system> _camera_system;
std::unique_ptr<gameplay::Enemy_system> _enemy_system;
std::unique_ptr<gameplay::Dash_system> _dash_system;
std::unique_ptr<gameplay::Beat_system> _beat_system;
std::unique_ptr<level::Level_system> _level_system;
std::unique_ptr<gameplay::Movement_system> _movement_system;
std::unique_ptr<input::Input_system> _input_system;
std::unique_ptr<gameplay::Combat_system> _combat_system;
std::unique_ptr<helper::Attachment_system> _attachment_system;
std::unique_ptr<ui::Hud_system> _hud_system;
std::unique_ptr<gameplay::Camera_system> _camera_system;
std::unique_ptr<gameplay::Enemy_system> _enemy_system;
std::unique_ptr<gameplay::Dash_system> _dash_system;
std::unique_ptr<gameplay::Stationary_attack_system> _stationary_attack_system;
std::unique_ptr<ui::Effect_system> _effect_system;
std::unique_ptr<ui::Effect_system> _effect_system;
mirrage::util::Console_command_container _commands;
};
......
#include "effect_system.hpp"
#include "../gameplay/combat_system.hpp"
#include "../gameplay/player_comp.hpp"
#include "../messages.hpp"
#include <mirrage/ecs/entity_manager.hpp>
......@@ -13,6 +15,8 @@ namespace phase_shifter::ui {
: _bus(bus), _mailbox(bus), _ecs(ecs)
{
_mailbox.subscribe_to([&](Enemy_killed_msg& e) {
_bus.send<Play_sound_msg>("enemy_hit"_strid);
auto entity = _ecs.entity_builder("enemy_tombstone")
.rotation(glm::rotation(
glm::vec3{1.f, 0.f, 0.f},
......@@ -20,17 +24,22 @@ namespace phase_shifter::ui {
.position(e.position)
.create();
_actions.defer(5_s, [&, entity] {
_ecs.erase(entity);
LOG(plog::debug) << "erased";
_actions.defer(5_s, [&, entity] { _ecs.erase(entity); });
});
_mailbox.subscribe_to([&](gameplay::Damaged_msg& e) {
_ecs.get(e.entity).process([&](auto& entity) {
entity.process([&](gameplay::Player_comp&) { _bus.send<Play_sound_msg>("damaged"_strid); });
});
});
_mailbox.subscribe_to([&](Win_msg& e) {
_bus.send<Play_sound_msg>("win"_strid);
// TODO
});
_mailbox.subscribe_to([&](Lose_msg& e) {
_bus.send<Play_sound_msg>("gameover"_strid);
// TODO
});
}
......
#pragma once
#include <algorithm>
#include <random>
#include <vector>
namespace phase_shifter::utils {
template <class T>
class Random_vector {
public:
Random_vector(std::vector<T> data = {}) : _data(std::move(data)) {}
auto raw_vector() -> std::vector<T>& { return _data; }
auto empty() const { return _data.empty(); }
template <class RNG>
auto get_random(RNG& gen) -> T&
{
if(_data.size() <= 1)
return _data.front();
if(_next_index < _data.size())
return _data[_next_index++];
if(_data.size() > 2) {
auto low = static_cast<std::size_t>(std::ceil(_data.size() / 4.f));
auto high = static_cast<std::size_t>(std::floor(_data.size() / 4.f * 3.f));
std::shuffle(_data.begin(), _data.begin() + high, gen);
std::shuffle(_data.begin() + low, _data.end(), gen);
}
_next_index = 1;
return _data[0];
}
private:
std::vector<T> _data;
std::size_t _next_index = 0;
};
} // namespace phase_shifter::utils
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment