Commit 4e3dcca4 authored by Kevin Balz's avatar Kevin Balz

Stationary attack

parent 13e5455c
Pipeline #3318 failed with stage
in 2 minutes and 15 seconds
......@@ -21,6 +21,9 @@
"Player": {},
"Dash": {
"attack_width": 0.8
},
"Stationary_attack": {
"radius": 3
},
"Rigid_body": {
"radius": 0.5
......
......@@ -24,6 +24,8 @@ namespace phase_shifter::gameplay {
float step_time = 0;
glm::vec2 last_step;
glm::vec2 last_aim;
bool attack = false;
};
sf2_structDef(Movement_comp,
......
......@@ -60,6 +60,7 @@ namespace phase_shifter::gameplay {
auto aim_len = glm::length(move.aim);
if(aim_len < 0.0001f) {
// TODO: attack
move.attack = true;
} else {
// start movement
move.beats_since_move = 0;
......
#include "stationary_attack_comp.hpp"
\ No newline at end of file
#pragma once
#include <mirrage/ecs/ecs.hpp>
#include <mirrage/utils/sf2_glm.hpp>
#include <mirrage/utils/units.hpp>
namespace phase_shifter::gameplay {
struct Stationary_attack_comp : public mirrage::ecs::Component<Stationary_attack_comp> {
static constexpr const char* name() { return "Stationary_attack"; }
using Component::Component;
float radius = 1;
};
sf2_structDef(Stationary_attack_comp, radius);
} // namespace phase_shifter::gameplay
\ No newline at end of file
#include "stationary_attack_system.hpp"
#include "killable_comp.hpp"
#include "movement_comp.hpp"
#include "stationary_attack_comp.hpp"
#include "../messages.hpp"
#include <mirrage/ecs/components/transform_comp.hpp>
#include <mirrage/ecs/ecs.hpp>
#include <mirrage/ecs/entity_set_view.hpp>
namespace phase_shifter::gameplay {
using mirrage::ecs::Entity_handle;
using mirrage::ecs::components::Transform_comp;
Stationary_attack_system::Stationary_attack_system(mirrage::util::Message_bus& bus,
mirrage::ecs::Entity_manager& entities)
: _bus(bus), _ecs(entities)
{
_ecs.register_component_type<Stationary_attack_comp>();
}
void Stationary_attack_system::update(mirrage::util::Time dt)
{
for(auto&& [transform, move, attack] :
_ecs.list<Transform_comp, Movement_comp, Stationary_attack_comp>()) {
glm::vec2 position(transform.position.x, transform.position.z);
if(move.attack) {
std::cout << "Attack!" << std::endl;
move.attack = false;
for(auto&& [entity, k_transform, kill] :
_ecs.list<Entity_handle, Transform_comp, Killable_comp>()) {
glm::vec2 k_position(k_transform.position.x, k_transform.position.z);
if(glm::length(position - k_position) < attack.radius + 1) {
auto attack_direction = glm::normalize(k_position - position);
_bus.send<Enemy_killed_msg>(k_transform.position, glm::vec3(attack_direction.x, 0, attack_direction.y));
_ecs.erase(entity);
}
}
}
}
}
} // namespace phase_shifter::gameplay
\ No newline at end of file
#pragma once
#include <mirrage/utils/messagebus.hpp>
#include <mirrage/utils/units.hpp>
namespace mirrage::ecs {
class Entity_manager;
}
namespace phase_shifter::gameplay {
class Stationary_attack_system {
public:
Stationary_attack_system(mirrage::util::Message_bus&, mirrage::ecs::Entity_manager&);
void update(mirrage::util::Time);
private:
mirrage::util::Message_bus& _bus;
mirrage::ecs::Entity_manager& _ecs;
};
} // namespace phase_shifter::gameplay
\ No newline at end of file
......@@ -6,6 +6,7 @@
#include "gameplay/camera_system.hpp"
#include "gameplay/combat_system.hpp"
#include "gameplay/dash_system.hpp"
#include "gameplay/Stationary_attack_system.hpp"
#include "gameplay/enemy_system.hpp"
#include "gameplay/killable_comp.hpp"
#include "gameplay/movement_system.hpp"
......@@ -44,6 +45,7 @@ namespace phase_shifter {
, _camera_system(std::make_unique<gameplay::Camera_system>(_entities))
, _enemy_system(std::make_unique<gameplay::Enemy_system>(_entities))
, _dash_system(std::make_unique<gameplay::Dash_system>(engine.bus(), _entities))
, _stationary_attack_system(std::make_unique<gameplay::Stationary_attack_system>(engine.bus(), _entities))
, _effect_system(std::make_unique<ui::Effect_system>(engine.bus(), _entities))
{
_entities.register_component_type<ecs::components::Transform_comp>();
......@@ -104,6 +106,7 @@ namespace phase_shifter {
_input_system->update(dt);
_level_system->update(dt);
_dash_system->update(dt);
_stationary_attack_system->update(dt);
_movement_system->update(dt);
_combat_system->update(dt);
_camera_system->update(dt);
......
......@@ -26,6 +26,7 @@ namespace phase_shifter {
class Enemy_system;
class Combat_system;
class Dash_system;
class Stationary_attack_system;
} // namespace gameplay
namespace helper {
class Attachment_system;
......@@ -74,6 +75,7 @@ namespace phase_shifter {
std::unique_ptr<gameplay::Camera_system> _camera_system;
std::unique_ptr<gameplay::Enemy_system> _enemy_system;
std::unique_ptr<gameplay::Dash_system> _dash_system;
std::unique_ptr<gameplay::Stationary_attack_system> _stationary_attack_system;
std::unique_ptr<ui::Effect_system> _effect_system;
mirrage::util::Console_command_container _commands;
......
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