Commit a1a9b8d8 authored by Kevin Balz's avatar Kevin Balz

Merge branch 'develop' into feature/36-level-design

parents 0502b5ca ed512969
Pipeline #3432 passed with stage
in 3 minutes and 47 seconds
...@@ -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": {}
} }
...@@ -42,6 +42,7 @@ namespace phase_shifter::gameplay { ...@@ -42,6 +42,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);
} }
} }
......
...@@ -238,6 +238,7 @@ namespace phase_shifter::gameplay { ...@@ -238,6 +238,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};
}; };
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,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>
...@@ -84,6 +85,10 @@ namespace phase_shifter::level { ...@@ -84,6 +85,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(
......
...@@ -13,7 +13,7 @@ namespace phase_shifter::ui { ...@@ -13,7 +13,7 @@ namespace phase_shifter::ui {
using namespace mirrage::gui::literals; using namespace mirrage::gui::literals;
namespace { namespace {
constexpr auto hud_height = 100; constexpr auto hud_height = 130;
constexpr auto bar_height = 80; constexpr auto bar_height = 80;
constexpr auto beat_bar_height = 79; constexpr auto beat_bar_height = 79;
constexpr auto bar_speed = 100; constexpr auto bar_speed = 100;
...@@ -38,35 +38,24 @@ namespace phase_shifter::ui { ...@@ -38,35 +38,24 @@ namespace phase_shifter::ui {
if(font.is_some()) if(font.is_some())
ImGui::PushFont(font.get_or_throw()); ImGui::PushFont(font.get_or_throw());
ImGui::PositionNextWindow(glm::vec2(viewport.z, hud_height), ImGui::PushStyleColor(ImGuiCol_WindowBg, ImColor(0, 0, 0, 180).Value);
ImGui::WindowPosition_X::left, ImGui::PushStyleColor(ImGuiCol_Border, ImColor(0, 0, 0, 0).Value);
ImGui::WindowPosition_Y::top);
if(ImGui::Begin("hud",
nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs)) {
ImGui::Text("%i", _beat_system.beat_state().beats_left);
ImGui::End();
}
ImGui::PositionNextWindow(glm::vec2(viewport.z, hud_height), ImGui::PositionNextWindow(glm::vec2(viewport.z, hud_height),
ImGui::WindowPosition_X::center, ImGui::WindowPosition_X::center,
ImGui::WindowPosition_Y::bottom); ImGui::WindowPosition_Y::bottom);
if(ImGui::Begin("beat", if(ImGui::Begin("beat",
nullptr, nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs)) { | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoScrollbar)) {
ImGui::PushStyleColor(ImGuiCol_Border, "#00000000"_imcolor.Value); // Hide Border ImGui::PushStyleColor(ImGuiCol_Border, "#00000000"_imcolor.Value); // Hide Border
ImVec2 cursor = ImGui::GetCursorScreenPos(); ImVec2 cursor = ImGui::GetCursorScreenPos();
cursor.y += hud_height / 2.f - 10; cursor.y += hud_height / 2.f + 10;
auto beat_state = _beat_system.beat_state(); auto beat_state = _beat_system.beat_state();
auto beats = _beat_system.time_stamps(); auto beats = _beat_system.time_stamps();
auto beat_index = _beat_system.beat_index() + 1; auto beat_index = _beat_system.beat_index() + 1;
//auto line_offset = bar_speed * beat_state.avg_beat_time; //auto line_offset = bar_speed * beat_state.avg_beat_time;
//auto beats = std::clamp(beat_state.beats_left, 0, 5); //auto beats = std::clamp(beat_state.beats_left, 0, 5);
ImGui::BeginChild("Line", {viewport.z, bar_height}, true); ImGui::BeginChild("Line", {viewport.z, hud_height}, true);
ImDrawList* drawList = ImGui::GetWindowDrawList(); ImDrawList* drawList = ImGui::GetWindowDrawList();
while (beat_index < static_cast<int>(beats.size())) { while (beat_index < static_cast<int>(beats.size())) {
...@@ -81,16 +70,27 @@ namespace phase_shifter::ui { ...@@ -81,16 +70,27 @@ namespace phase_shifter::ui {
auto bar_color = ImGui::ColorConvertFloat4ToU32(bar_color_float); auto bar_color = ImGui::ColorConvertFloat4ToU32(bar_color_float);
ImVec2 p(cursor.x + viewport.z / 2 - x_offset, cursor.y - height / 2.f); ImVec2 p(cursor.x + viewport.z / 2 - x_offset, cursor.y - height / 2.f);
drawList->AddLine(p, {p.x, p.y + height}, bar_color, 1); drawList->AddLine(p, {p.x, p.y + height}, bar_color, 2);
p.x = cursor.x + viewport.z / 2 + x_offset; p.x = cursor.x + viewport.z / 2 + x_offset;
drawList->AddLine(p, {p.x, p.y + height}, bar_color, 1); drawList->AddLine(p, {p.x, p.y + height}, bar_color, 2);
beat_index++; beat_index++;
} }
ImVec2 middle(cursor.x + viewport.z / 2, cursor.y - bar_height / 2.f); ImVec2 middle(cursor.x + viewport.z / 2, cursor.y - bar_height / 2.f);
drawList->AddLine(middle, {middle.x, middle.y + bar_height}, 0xFFFF0000, 4); drawList->AddLine(middle, {middle.x, middle.y + bar_height}, 0xFFFF0000, 6);
auto beat_color = (_beat_system.beat_state().beats_left < 50
&& _beat_system.beat_state().beats_left % 2 == 0)
? ImColor(255, 0, 0)
: ImColor(255, 255, 255);
auto beats_left = std::to_string(_beat_system.beat_state().beats_left);
auto text_size = ImGui::CalcTextSize(beats_left.c_str());
drawList->AddText(ImVec2(middle.x - text_size.x / 2.f, middle.y - text_size.y - 10),
beat_color,
beats_left.c_str());
ImGui::EndChild(); ImGui::EndChild();
ImGui::PopStyleColor(); ImGui::PopStyleColor();
...@@ -105,6 +105,9 @@ namespace phase_shifter::ui { ...@@ -105,6 +105,9 @@ namespace phase_shifter::ui {
} }
} }
ImGui::PopStyleColor();
ImGui::PopStyleColor();
if(font.is_some()) if(font.is_some())
ImGui::PopFont(); ImGui::PopFont();
} }
......
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