Commit cd6af511 authored by Georg Schäfer's avatar Georg Schäfer

Merge branch 'develop' of...

Merge branch 'develop' of gitlab.fsi.hochschule-trier.de:GameDevWeek/sommersemester-2019/cpp/phaseshifter into develop
parents af485b35 ed512969
...@@ -18,5 +18,6 @@ ...@@ -18,5 +18,6 @@
"Spring": { "Spring": {
"spring_constant": 20.0, "spring_constant": 20.0,
"mass": 1.0 "mass": 1.0
} },
"Shake": {}
} }
...@@ -40,6 +40,7 @@ namespace phase_shifter::gameplay { ...@@ -40,6 +40,7 @@ namespace phase_shifter::gameplay {
if(beat) { if(beat) {
_beat_index++; _beat_index++;
LOG(plog::debug) << "beat"; LOG(plog::debug) << "beat";
_bus.send<Screen_shake_msg>(0.03f, 0.05f);
beats_left = size - 1 - _beat_index + _beat_offset; beats_left = size - 1 - _beat_index + _beat_offset;
if(beats_left <= 0 || _beat_index + 1 >= size) { if(beats_left <= 0 || _beat_index + 1 >= size) {
......
...@@ -6,17 +6,28 @@ namespace phase_shifter::gameplay { ...@@ -6,17 +6,28 @@ namespace phase_shifter::gameplay {
using mirrage::ecs::components::Transform_comp; using mirrage::ecs::components::Transform_comp;
Camera_system::Camera_system(mirrage::ecs::Entity_manager& entity_manager) Camera_system::Camera_system(mirrage::util::Message_bus& bus, mirrage::ecs::Entity_manager& entity_manager)
: _entity_manager(entity_manager) : _entity_manager(entity_manager), _mailbox(bus)
{ {
_entity_manager.register_component_type<Viewtarget_comp>(); _entity_manager.register_component_type<Viewtarget_comp>();
_entity_manager.register_component_type<Spring_comp>(); _entity_manager.register_component_type<Spring_comp>();
_entity_manager.register_component_type<Shake_comp>();
_mailbox.subscribe_to([&](Screen_shake_msg& e) {
for (auto& shake : _entity_manager.list<Shake_comp>()) {
shake.intesity = e.intensity;
shake.duration = e.duration;
shake.time_remaining = e.duration;
}
});
} }
void Camera_system::update(mirrage::util::Time dt) void Camera_system::update(mirrage::util::Time dt)
{ {
for(auto&& [transform, viewtarget, spring] : _mailbox.update_subscriptions();
_entity_manager.list<Transform_comp, Viewtarget_comp, Spring_comp>()) {
for(auto&& [transform, viewtarget, spring, shake] :
_entity_manager.list<Transform_comp, Viewtarget_comp, Spring_comp, Shake_comp>()) {
auto target_facet = _entity_manager.get(viewtarget.target); auto target_facet = _entity_manager.get(viewtarget.target);
if(target_facet.is_some()) { if(target_facet.is_some()) {
...@@ -35,7 +46,13 @@ namespace phase_shifter::gameplay { ...@@ -35,7 +46,13 @@ namespace phase_shifter::gameplay {
glm::vec3 spring_force = spring.spring_constant * (dest_pos - transform.position); glm::vec3 spring_force = spring.spring_constant * (dest_pos - transform.position);
glm::vec3 acceleration = (spring_force + damping_force) / spring.mass; glm::vec3 acceleration = (spring_force + damping_force) / spring.mass;
spring.velocity += dt.value() * acceleration; 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); transform.direction(-offset);
} }
} }
......
...@@ -2,18 +2,23 @@ ...@@ -2,18 +2,23 @@
#include <mirrage/utils/units.hpp> #include <mirrage/utils/units.hpp>
#include <mirrage/ecs/entity_manager.hpp> #include <mirrage/ecs/entity_manager.hpp>
#include <mirrage/utils/messagebus.hpp>
#include "../messages.hpp"
#include "viewtarget_comp.hpp" #include "viewtarget_comp.hpp"
#include "spring_comp.hpp" #include "spring_comp.hpp"
#include "shake_comp.hpp"
namespace phase_shifter::gameplay { namespace phase_shifter::gameplay {
class Camera_system { class Camera_system {
public: 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); void update(mirrage::util::Time dt);
private: private:
mirrage::ecs::Entity_manager& _entity_manager; mirrage::ecs::Entity_manager& _entity_manager;
mirrage::util::Mailbox_collection _mailbox;
}; };
} }
\ No newline at end of file
...@@ -115,6 +115,7 @@ namespace phase_shifter::gameplay { ...@@ -115,6 +115,7 @@ namespace phase_shifter::gameplay {
_bus.send<Enemy_killed_msg>(k_transform.position, _bus.send<Enemy_killed_msg>(k_transform.position,
glm::vec3(attack_direction.x, 0.f, attack_direction.y)); glm::vec3(attack_direction.x, 0.f, attack_direction.y));
_bus.send<Screen_shake_msg>(0.5f, 0.3f);
_ecs.erase(entity); _ecs.erase(entity);
} }
} }
......
...@@ -221,6 +221,7 @@ namespace phase_shifter::gameplay { ...@@ -221,6 +221,7 @@ namespace phase_shifter::gameplay {
Stadium{last_player_pos, player_pos, player_body.radius})) { Stadium{last_player_pos, player_pos, player_body.radius})) {
_entity_manager.erase(bullet_handle); _entity_manager.erase(bullet_handle);
_bus.send<Damaged_msg>(player_handle); _bus.send<Damaged_msg>(player_handle);
_bus.send<Screen_shake_msg>(0.3f, 0.3f);
} }
} }
} }
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "beat_system.hpp" #include "beat_system.hpp"
#include "../messages.hpp"
namespace phase_shifter::gameplay { namespace phase_shifter::gameplay {
struct Stadium { struct Stadium {
......
#pragma once
#include <mirrage/ecs/ecs.hpp>
#include <mirrage/utils/sf2_glm.hpp>
namespace phase_shifter::gameplay {
struct Shake_comp : public mirrage::ecs::Component<Shake_comp> {
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
...@@ -12,6 +12,7 @@ namespace phase_shifter::gameplay { ...@@ -12,6 +12,7 @@ namespace phase_shifter::gameplay {
float spring_constant = 1.f; float spring_constant = 1.f;
float mass = 1.f; float mass = 1.f;
glm::vec3 position = {0.f, 0.f, 0.f};
glm::vec3 velocity = {0.f, 0.f, 0.f}; glm::vec3 velocity = {0.f, 0.f, 0.f};
}; };
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "../gameplay/player_comp.hpp" #include "../gameplay/player_comp.hpp"
#include "../gameplay/rigid_body_comp.hpp" #include "../gameplay/rigid_body_comp.hpp"
#include "../gameplay/viewtarget_comp.hpp" #include "../gameplay/viewtarget_comp.hpp"
#include "../gameplay/spring_comp.hpp"
#include "../helper/attachment_comp.hpp" #include "../helper/attachment_comp.hpp"
#include <mirrage/ecs/components/transform_comp.hpp> #include <mirrage/ecs/components/transform_comp.hpp>
...@@ -82,6 +83,10 @@ namespace phase_shifter::level { ...@@ -82,6 +83,10 @@ namespace phase_shifter::level {
entity.process([=](gameplay::Viewtarget_comp& viewtarget) { entity.process([=](gameplay::Viewtarget_comp& viewtarget) {
viewtarget.target = playerhandle; viewtarget.target = playerhandle;
}); });
entity.process(
[=](gameplay::Spring_comp& spring, Transform_comp& transform) {
spring.position = transform.position;
});
}) })
.create(); .create();
......
...@@ -29,4 +29,9 @@ namespace phase_shifter { ...@@ -29,4 +29,9 @@ namespace phase_shifter {
mirrage::util::Str_id id; mirrage::util::Str_id id;
}; };
struct Screen_shake_msg {
float intensity;
float duration; //duration in seconds
};
} // namespace phase_shifter } // namespace phase_shifter
...@@ -43,7 +43,7 @@ namespace phase_shifter { ...@@ -43,7 +43,7 @@ namespace phase_shifter {
, _combat_system(std::make_unique<gameplay::Combat_system>(engine.bus(), _entities, *_beat_system)) , _combat_system(std::make_unique<gameplay::Combat_system>(engine.bus(), _entities, *_beat_system))
, _attachment_system(std::make_unique<helper::Attachment_system>(_entities)) , _attachment_system(std::make_unique<helper::Attachment_system>(_entities))
, _hud_system(std::make_unique<ui::Hud_system>(engine.gui(), _entities, *_beat_system)) , _hud_system(std::make_unique<ui::Hud_system>(engine.gui(), _entities, *_beat_system))
, _camera_system(std::make_unique<gameplay::Camera_system>(_entities)) , _camera_system(std::make_unique<gameplay::Camera_system>(engine.bus(), _entities))
, _enemy_system(std::make_unique<gameplay::Enemy_system>(engine.bus(), _entities, *_beat_system)) , _enemy_system(std::make_unique<gameplay::Enemy_system>(engine.bus(), _entities, *_beat_system))
, _dash_system(std::make_unique<gameplay::Dash_system>(engine.bus(), _entities)) , _dash_system(std::make_unique<gameplay::Dash_system>(engine.bus(), _entities))
, _stationary_attack_system( , _stationary_attack_system(
......
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