diff --git a/assets/game_assets/blueprints/camera.json b/assets/game_assets/blueprints/camera.json index 9542170b568059b98a0741e8a3932a428988a641..133700634fbce8b3557bd197d3c0c4943794995c 100644 --- a/assets/game_assets/blueprints/camera.json +++ b/assets/game_assets/blueprints/camera.json @@ -18,5 +18,6 @@ "Spring": { "spring_constant": 20.0, "mass": 1.0 - } + }, + "Shake": {} } diff --git a/src/gameplay/beat_system.cpp b/src/gameplay/beat_system.cpp index 54c3845e387e81c81d7e1f6d5be10a14eb08cc3d..e086964887ccd53288d2ee27f9af4ab51a0076e2 100644 --- a/src/gameplay/beat_system.cpp +++ b/src/gameplay/beat_system.cpp @@ -40,6 +40,7 @@ namespace phase_shifter::gameplay { if(beat) { _beat_index++; LOG(plog::debug) << "beat"; + _bus.send(0.03f, 0.05f); beats_left = size - 1 - _beat_index + _beat_offset; if(beats_left <= 0 || _beat_index + 1 >= size) { diff --git a/src/gameplay/camera_system.cpp b/src/gameplay/camera_system.cpp index 91d2681994764685a61501226d1e4a5d77698d4d..09e06403a9ee8b0ec04dccc2b3c534f18f9a4d5d 100644 --- a/src/gameplay/camera_system.cpp +++ b/src/gameplay/camera_system.cpp @@ -6,17 +6,28 @@ namespace phase_shifter::gameplay { using mirrage::ecs::components::Transform_comp; - Camera_system::Camera_system(mirrage::ecs::Entity_manager& entity_manager) - : _entity_manager(entity_manager) + Camera_system::Camera_system(mirrage::util::Message_bus& bus, mirrage::ecs::Entity_manager& entity_manager) + : _entity_manager(entity_manager), _mailbox(bus) { _entity_manager.register_component_type(); _entity_manager.register_component_type(); + _entity_manager.register_component_type(); + + _mailbox.subscribe_to([&](Screen_shake_msg& e) { + for (auto& shake : _entity_manager.list()) { + shake.intesity = e.intensity; + shake.duration = e.duration; + shake.time_remaining = e.duration; + } + }); } void Camera_system::update(mirrage::util::Time dt) { - for(auto&& [transform, viewtarget, spring] : - _entity_manager.list()) { + _mailbox.update_subscriptions(); + + for(auto&& [transform, viewtarget, spring, shake] : + _entity_manager.list()) { auto target_facet = _entity_manager.get(viewtarget.target); if(target_facet.is_some()) { @@ -35,7 +46,13 @@ namespace phase_shifter::gameplay { glm::vec3 spring_force = spring.spring_constant * (dest_pos - transform.position); glm::vec3 acceleration = (spring_force + damping_force) / spring.mass; spring.velocity += dt.value() * acceleration; - transform.position += dt.value() * spring.velocity; + spring.position += dt.value() * spring.velocity; + transform.position = spring.position; + if (shake.time_remaining > 0) { + glm::vec3 shake_direction = glm::normalize(glm::vec3{std::rand(), 0, std::rand()}); + transform.position += shake.intesity * (shake.time_remaining / shake.duration) * shake_direction; + shake.time_remaining -= dt.value(); + } transform.direction(-offset); } } diff --git a/src/gameplay/camera_system.hpp b/src/gameplay/camera_system.hpp index 9061564116048d578bfe92ddb9bd06bf5b02e191..d0c13f3a47703702cc4efb56c7c23dd408bd56d3 100644 --- a/src/gameplay/camera_system.hpp +++ b/src/gameplay/camera_system.hpp @@ -2,18 +2,23 @@ #include #include +#include + +#include "../messages.hpp" #include "viewtarget_comp.hpp" #include "spring_comp.hpp" +#include "shake_comp.hpp" namespace phase_shifter::gameplay { class Camera_system { public: - Camera_system(mirrage::ecs::Entity_manager& entity_manager); + Camera_system(mirrage::util::Message_bus& bus, mirrage::ecs::Entity_manager& entity_manager); void update(mirrage::util::Time dt); private: mirrage::ecs::Entity_manager& _entity_manager; + mirrage::util::Mailbox_collection _mailbox; }; } \ No newline at end of file diff --git a/src/gameplay/dash_system.cpp b/src/gameplay/dash_system.cpp index 65c4f83dd1c81cb2972d8b229be8dfbc0ce9c6d6..5888ba021eb6b326964db197cd8614813164ca4a 100644 --- a/src/gameplay/dash_system.cpp +++ b/src/gameplay/dash_system.cpp @@ -115,6 +115,7 @@ namespace phase_shifter::gameplay { _bus.send(k_transform.position, glm::vec3(attack_direction.x, 0.f, attack_direction.y)); + _bus.send(0.5f, 0.3f); _ecs.erase(entity); } } diff --git a/src/gameplay/enemy_system.cpp b/src/gameplay/enemy_system.cpp index 4e887969e0ad42276ccb7c1e3ad5393ac5916e46..14f8a0a70885da62f08c5472d2d6b5ac9bf8f985 100644 --- a/src/gameplay/enemy_system.cpp +++ b/src/gameplay/enemy_system.cpp @@ -221,6 +221,7 @@ namespace phase_shifter::gameplay { Stadium{last_player_pos, player_pos, player_body.radius})) { _entity_manager.erase(bullet_handle); _bus.send(player_handle); + _bus.send(0.3f, 0.3f); } } } diff --git a/src/gameplay/enemy_system.hpp b/src/gameplay/enemy_system.hpp index 00ba9709bf9c40b2a936ce84e9ef5d3303786e7f..318f88bfa601a496ba09203fcd71b17e6e52b577 100644 --- a/src/gameplay/enemy_system.hpp +++ b/src/gameplay/enemy_system.hpp @@ -12,6 +12,8 @@ #include "beat_system.hpp" +#include "../messages.hpp" + namespace phase_shifter::gameplay { struct Stadium { diff --git a/src/gameplay/shake_comp.hpp b/src/gameplay/shake_comp.hpp new file mode 100644 index 0000000000000000000000000000000000000000..957ea2bbdc5bfad96ca036b263d5a57027345c66 --- /dev/null +++ b/src/gameplay/shake_comp.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +namespace phase_shifter::gameplay { + + struct Shake_comp : public mirrage::ecs::Component { + static constexpr const char* name() { return "Shake"; } + using Component::Component; + + float intesity = 0; + float duration = 0; //duration in seconds + float time_remaining = 0; //remaining shake time in seconds + }; +} // namespace phase_shifter::gameplay diff --git a/src/gameplay/spring_comp.hpp b/src/gameplay/spring_comp.hpp index ea9b8d64461bb26a0c010a872ae760fc69d7883f..75d48317931b02cb5020322c06ad6e9b0c74c566 100644 --- a/src/gameplay/spring_comp.hpp +++ b/src/gameplay/spring_comp.hpp @@ -12,6 +12,7 @@ namespace phase_shifter::gameplay { float spring_constant = 1.f; float mass = 1.f; + glm::vec3 position = {0.f, 0.f, 0.f}; glm::vec3 velocity = {0.f, 0.f, 0.f}; }; diff --git a/src/level/level_system.cpp b/src/level/level_system.cpp index 85ce637b39612741232aa3c1e1e9e1d8ddc873be..8dc9d22f74d1465fe0b47ce6d0fc88ce764cd575 100644 --- a/src/level/level_system.cpp +++ b/src/level/level_system.cpp @@ -4,6 +4,7 @@ #include "../gameplay/player_comp.hpp" #include "../gameplay/rigid_body_comp.hpp" #include "../gameplay/viewtarget_comp.hpp" +#include "../gameplay/spring_comp.hpp" #include "../helper/attachment_comp.hpp" #include @@ -82,6 +83,10 @@ namespace phase_shifter::level { entity.process([=](gameplay::Viewtarget_comp& viewtarget) { viewtarget.target = playerhandle; }); + entity.process( + [=](gameplay::Spring_comp& spring, Transform_comp& transform) { + spring.position = transform.position; + }); }) .create(); diff --git a/src/messages.hpp b/src/messages.hpp index 87e1383b149242840ce0b1f1a6dcf343b8a13304..eb6b1c7bd370ca6a3f77333b0b49905a47eeb1c7 100644 --- a/src/messages.hpp +++ b/src/messages.hpp @@ -29,4 +29,9 @@ namespace phase_shifter { mirrage::util::Str_id id; }; + struct Screen_shake_msg { + float intensity; + float duration; //duration in seconds + }; + } // namespace phase_shifter diff --git a/src/meta_system.cpp b/src/meta_system.cpp index 562b7727149cd5576be6ff8b49b32cce19a1b8e9..08b4efb17d994078bec8958ac53a0f4f4bf86573 100644 --- a/src/meta_system.cpp +++ b/src/meta_system.cpp @@ -43,7 +43,7 @@ namespace phase_shifter { , _combat_system(std::make_unique(engine.bus(), _entities, *_beat_system)) , _attachment_system(std::make_unique(_entities)) , _hud_system(std::make_unique(engine.gui(), _entities, *_beat_system)) - , _camera_system(std::make_unique(_entities)) + , _camera_system(std::make_unique(engine.bus(), _entities)) , _enemy_system(std::make_unique(engine.bus(), _entities, *_beat_system)) , _dash_system(std::make_unique(engine.bus(), _entities)) , _stationary_attack_system(