Commit a8f92995 authored by Florian Oetke's avatar Florian Oetke
Browse files

win condition

parent 8d29140a
......@@ -2,6 +2,7 @@
"Transform":{
"scale": {"x": 1.0, "y": 1.0, "z": 1.0}
},
"Goal": {},
"Particle_system": {
"cfg": "particle_sys:test_particles"
}
......
......@@ -5,6 +5,6 @@ dummy
#| p h |#
#| |---- b |#
##----####| |#
##########| b |#
##########| b G|#
###########-----##
##################
......@@ -34,6 +34,12 @@
"solid": false,
"spawn": true,
"spawns": "basic_enemy"
},
"G": {
"blueprint": "dummy_floor",
"solid": false,
"spawn": true,
"spawns": "goal"
}
}
}
#include "combat_system.hpp"
#include "goal_comp.hpp"
#include "player_comp.hpp"
#include "../messages.hpp"
#include <mirrage/ecs/components/transform_comp.hpp>
#include <mirrage/ecs/entity_set_view.hpp>
namespace phase_shifter::gameplay {
using mirrage::ecs::components::Transform_comp;
namespace {
constexpr auto damage_beat_penalty = 10;
}
......@@ -12,9 +20,10 @@ namespace phase_shifter::gameplay {
Combat_system::Combat_system(mirrage::util::Message_bus& bus,
mirrage::ecs::Entity_manager& ecs,
Beat_system& beats)
: _mailbox(bus), _ecs(ecs), _beat_system(beats)
: _bus(bus), _mailbox(bus), _ecs(ecs), _beat_system(beats)
{
_ecs.register_component_type<Player_comp>();
_ecs.register_component_type<Goal_comp>();
_mailbox.subscribe_to([&](Damaged_msg& e) {
_ecs.get(e.entity).process([&](auto& entity) {
......@@ -26,7 +35,18 @@ namespace phase_shifter::gameplay {
void Combat_system::update(mirrage::util::Time)
{
_mailbox.update_subscriptions();
// TODO
if(_game_won)
return;
for(auto&& [player_transform, p] : _ecs.list<Transform_comp, Player_comp>()) {
for(auto&& [transform, goal] : _ecs.list<Transform_comp, Goal_comp>()) {
if(glm::distance2(player_transform.position, transform.position) < 1.f) {
_game_won = true;
_bus.send<Win_msg>();
}
}
}
}
} // namespace phase_shifter::gameplay
......@@ -24,9 +24,12 @@ namespace phase_shifter::gameplay {
void update(mirrage::util::Time);
private:
mirrage::util::Message_bus& _bus;
mirrage::util::Mailbox_collection _mailbox;
mirrage::ecs::Entity_manager& _ecs;
Beat_system& _beat_system;
bool _game_won = false;
};
} // namespace phase_shifter::gameplay
#include "goal_comp.hpp"
#pragma once
#include <mirrage/ecs/ecs.hpp>
#include <mirrage/utils/sf2_glm.hpp>
#include <mirrage/utils/units.hpp>
namespace phase_shifter::gameplay {
struct Goal_comp : public mirrage::ecs::Stateless_tag_component<Goal_comp> {
static constexpr const char* name() { return "Goal"; }
using Stateless_tag_component::Stateless_tag_component;
};
} // namespace phase_shifter::gameplay
......@@ -86,9 +86,6 @@ namespace phase_shifter {
});
_level_system->load("dummy");
// TODO: remove
entities().entity_builder("test_particle_emitter").position(glm::vec3(11, 0, 11)).create();
}
Meta_system::~Meta_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