Commit 09d7e506 authored by Florian Oetke's avatar Florian Oetke
Browse files

decrease level timer on damage/missed beats [#9]

parent 396ec8c3
Pipeline #3245 passed with stage
in 3 minutes and 26 seconds
......@@ -21,4 +21,6 @@ namespace phase_shifter::gameplay {
_state = {beat, _acc, beat_time - _acc, beat_time, _state.beats_left};
}
void Beat_system::decrease_beats_left(int count) { _state.beats_left -= count; }
} // namespace phase_shifter::gameplay
......@@ -22,6 +22,8 @@ namespace phase_shifter::gameplay {
auto beat_state() const { return _state; }
void decrease_beats_left(int count);
private:
Beat_state _state;
float _acc = 0.f;
......
......@@ -5,17 +5,21 @@
namespace phase_shifter::gameplay {
Combat_system::Combat_system(mirrage::util::Message_bus& bus, mirrage::ecs::Entity_manager& ecs)
: _mailbox(bus), _ecs(ecs)
namespace {
constexpr auto damage_beat_penalty = 10;
}
Combat_system::Combat_system(mirrage::util::Message_bus& bus,
mirrage::ecs::Entity_manager& ecs,
Beat_system& beats)
: _mailbox(bus), _ecs(ecs), _beat_system(beats)
{
_ecs.register_component_type<Player_comp>();
_mailbox.subscribe_to([&](Damaged_msg& e) {
_ecs.get(e.entity).process([&](auto& entity) {
//entity.process<>();
// TODO
entity.process([&](Player_comp&) { _beat_system.decrease_beats_left(damage_beat_penalty); });
});
// TODO
});
}
......
#pragma once
#include "beat_system.hpp"
#include <mirrage/ecs/entity_handle.hpp>
#include <mirrage/utils/messagebus.hpp>
#include <mirrage/utils/units.hpp>
......@@ -17,13 +19,14 @@ namespace phase_shifter::gameplay {
class Combat_system {
public:
Combat_system(mirrage::util::Message_bus&, mirrage::ecs::Entity_manager&);
Combat_system(mirrage::util::Message_bus&, mirrage::ecs::Entity_manager&, Beat_system&);
void update(mirrage::util::Time);
private:
mirrage::util::Mailbox_collection _mailbox;
mirrage::ecs::Entity_manager& _ecs;
Beat_system& _beat_system;
};
} // namespace phase_shifter::gameplay
#include "movement_system.hpp"
#include "beat_system.hpp"
#include "combat_system.hpp"
#include "movement_comp.hpp"
#include <mirrage/ecs/components/transform_comp.hpp>
......@@ -12,8 +13,10 @@ namespace phase_shifter::gameplay {
using mirrage::ecs::components::Transform_comp;
Movement_system::Movement_system(mirrage::ecs::Entity_manager& ecs, const Beat_system& beat_system)
: _ecs(ecs), _beat_system(beat_system)
Movement_system::Movement_system(mirrage::util::Message_bus& bus,
mirrage::ecs::Entity_manager& ecs,
const Beat_system& beat_system)
: _bus(bus), _ecs(ecs), _beat_system(beat_system)
{
_ecs.register_component_type<Movement_comp>();
}
......@@ -28,13 +31,13 @@ namespace phase_shifter::gameplay {
}
if(move.move && move.beats_since_move >= move.beats_per_step
&& (beat.beat || move.off_beat_threshold > 0.0001f)) {
move.move = false;
auto allowed = (beat.beat || beat.time_since_beat <= move.off_beat_threshold
|| beat.time_to_beat <= move.off_beat_threshold)
&& move.beats_since_move >= move.beats_per_step;
auto allowed = beat.beat || beat.time_since_beat <= move.off_beat_threshold
|| beat.time_to_beat <= move.off_beat_threshold;
if(move.move && (allowed || move.off_beat_threshold > 0.0001f)) {
move.move = false;
if(allowed) {
auto aim_len = glm::length(move.aim);
......@@ -48,7 +51,7 @@ namespace phase_shifter::gameplay {
}
} else {
// TODO: damage
_bus.send<Damaged_msg>(transform.owner_handle());
LOG(plog::debug) << "miss";
}
}
......
#pragma once
#include <mirrage/utils/messagebus.hpp>
#include <mirrage/utils/units.hpp>
namespace mirrage::ecs {
......@@ -12,11 +13,12 @@ namespace phase_shifter::gameplay {
class Movement_system {
public:
Movement_system(mirrage::ecs::Entity_manager&, const Beat_system&);
Movement_system(mirrage::util::Message_bus&, mirrage::ecs::Entity_manager&, const Beat_system&);
void update(mirrage::util::Time);
private:
mirrage::util::Message_bus& _bus;
mirrage::ecs::Entity_manager& _ecs;
const Beat_system& _beat_system;
};
......
......@@ -11,7 +11,7 @@ using namespace mirrage::input;
namespace phase_shifter::input {
namespace {
constexpr auto key_move_delay = 0.04f;
constexpr auto key_move_delay = 0.01f;
}
Input_system::Input_system(mirrage::util::Message_bus& bus, mirrage::ecs::Entity_manager& ecs)
......
......@@ -4,6 +4,7 @@
#include "game_engine.hpp"
#include "gameplay/beat_system.hpp"
#include "gameplay/camera_system.hpp"
#include "gameplay/combat_system.hpp"
#include "gameplay/movement_system.hpp"
#include "helper/attachment_system.hpp"
#include "input/input_system.hpp"
......@@ -28,8 +29,9 @@ namespace phase_shifter {
, _renderer(engine.renderer_factory().create_renderer(_entities, engine.render_pass_mask()))
, _model_loading(std::make_unique<renderer::Loading_system>(_entities, engine.assets()))
, _beat_system(std::make_unique<gameplay::Beat_system>())
, _movement_system(std::make_unique<gameplay::Movement_system>(_entities, *_beat_system))
, _movement_system(std::make_unique<gameplay::Movement_system>(engine.bus(), _entities, *_beat_system))
, _input_system(std::make_unique<input::Input_system>(engine.bus(), _entities))
, _combat_system(std::make_unique<gameplay::Combat_system>(engine.bus(), _entities, *_beat_system))
, _attachment_system(std::make_unique<helper::Attachment_system>(_entities))
, _hud_system(std::make_unique<ui::Hud_system>(engine.gui(), _entities, *_beat_system))
, _camera_system(std::make_unique<gameplay::Camera_system>(_entities))
......@@ -132,6 +134,7 @@ namespace phase_shifter {
_beat_system->update(dt);
_input_system->update(dt);
_movement_system->update(dt);
_combat_system->update(dt);
_camera_system->update(dt);
_attachment_system->update(dt);
......
......@@ -23,6 +23,7 @@ namespace phase_shifter {
class Beat_system;
class Movement_system;
class Camera_system;
class Combat_system;
} // namespace gameplay
namespace helper {
class Attachment_system;
......@@ -59,6 +60,7 @@ namespace phase_shifter {
std::unique_ptr<gameplay::Beat_system> _beat_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;
......
......@@ -13,14 +13,13 @@ namespace phase_shifter::ui {
namespace {
constexpr auto hud_height = 100;
constexpr auto count_down = 300;
constexpr auto bar_speed = 100;
} // namespace
Hud_system::Hud_system(mirrage::gui::Gui& gui,
mirrage::ecs::Entity_manager& ecs,
const phase_shifter::gameplay::Beat_system& beat_system)
: _gui(gui), _ecs(ecs), _timeLeft(count_down), _beat_system(beat_system)
: _gui(gui), _ecs(ecs), _beat_system(beat_system)
{
//_circle_texture = _gui.load_texture("tex:circle"_aid);
_max_distance = gui.viewport().z / 2;
......@@ -28,7 +27,6 @@ namespace phase_shifter::ui {
void Hud_system::update(mirrage::util::Time dt)
{
_timeLeft -= dt;
auto state = _beat_system.beat_state();
int max_bars = static_cast<int>(_max_distance / (bar_speed * state.avg_beat_time) + 1);
if(state.beat && _beats < max_bars) {
......@@ -53,7 +51,7 @@ namespace phase_shifter::ui {
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoBackground)) {
ImGui::Text("%.2f", _timeLeft.value());
ImGui::Text("%i", _beat_system.beat_state().beats_left);
ImGui::End();
}
......@@ -65,10 +63,10 @@ namespace phase_shifter::ui {
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoBackground)) {
ImGui::PushStyleColor(ImGuiCol_Border, "#00000000"_imcolor.Value); // Hide Border
ImVec2 cursor = ImGui::GetCursorScreenPos();
auto beat_state = _beat_system.beat_state();
int max_bars = static_cast<int>(_max_distance / (bar_speed * beat_state.avg_beat_time) + 1);
auto line_offset = bar_speed * beat_state.avg_beat_time;
ImVec2 cursor = ImGui::GetCursorScreenPos();
auto beat_state = _beat_system.beat_state();
int max_bars = static_cast<int>(_max_distance / (bar_speed * beat_state.avg_beat_time) + 1);
auto line_offset = bar_speed * beat_state.avg_beat_time;
auto start_offset = (max_bars - _beats) * line_offset;
ImGui::BeginChild("Line", {viewport.z, 90}, true);
ImDrawList* drawList = ImGui::GetWindowDrawList();
......
#pragma once
#include "../gameplay/beat_system.hpp"
#include <mirrage/ecs/ecs.hpp>
#include <mirrage/gui/gui.hpp>
#include <mirrage/utils/units.hpp>
#include <unordered_map>
#include <memory>
#include "../gameplay/beat_system.hpp"
#include <unordered_map>
namespace phase_shifter::ui {
......@@ -16,15 +17,14 @@ namespace phase_shifter::ui {
Hud_system(mirrage::gui::Gui& gui,
mirrage::ecs::Entity_manager& ecs,
const phase_shifter::gameplay::Beat_system& beat_system);
void update(mirrage::util::Time dt);
void draw();
private:
mirrage::gui::Gui& _gui;
mirrage::ecs::Entity_manager& _ecs;
mirrage::util::Time _timeLeft;
int _beats = 0;
mirrage::gui::Gui& _gui;
mirrage::ecs::Entity_manager& _ecs;
int _beats = 0;
float _offset = 0;
float _max_distance;
const phase_shifter::gameplay::Beat_system& _beat_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