Commit 6fc1e13c authored by Tim Scheiber's avatar Tim Scheiber
Browse files

Added fixed path movement for enemies

parent 10133b11
Pipeline #3236 failed with stage
in 6 minutes and 31 seconds
{
"Transform": {
"scale": {
"x": 0.3,
"y": 0.3,
"z": 0.3
}
},
"Model": {
"aid": "model:cube"
},
"Shadowcaster": {
},
"Movement": {
"beats_per_step": 1,
"distance_per_step": 1,
"step_time_percentage": 0.2,
"off_beat_threshold": 0.2
},
"FixedPath": {
}
}
#include "enemy_system.hpp"
#include "movement_comp.hpp"
namespace phase_shifter::gameplay {
Enemy_system::Enemy_system(mirrage::ecs::Entity_manager& entity_manager) : _entity_manager(entity_manager)
{
_entity_manager.register_component_type<Fixed_path_comp>();
}
void Enemy_system::update(mirrage::util::Time dt)
{
for (auto&& [movement, fixed_path] : _entity_manager.list<Movement_comp, Fixed_path_comp>()) {
if (!movement.move) {
float rad_direction = fixed_path.next_direction() * mirrage::util::PI / 180.f;
if (rad_direction >= 0) {
movement.aim.x = std::sin(rad_direction);
movement.aim.y = -std::cos(rad_direction);
movement.move = true;
}
}
}
}
}
\ No newline at end of file
#pragma once
#include <mirrage/utils/units.hpp>
#include <mirrage/ecs/entity_manager.hpp>
#include "fixed_path_comp.hpp"
namespace phase_shifter::gameplay {
class Enemy_system {
public:
Enemy_system(mirrage::ecs::Entity_manager& entity_manager);
void update(mirrage::util::Time dt);
private:
mirrage::ecs::Entity_manager& _entity_manager;
};
}
\ No newline at end of file
#include "fixed_path_comp.hpp"
namespace phase_shifter::gameplay {
void Fixed_path_comp::update_path(std::vector<float> directions)
{
next_step = 0;
reverse = false;
this->directions = directions;
}
float Fixed_path_comp::next_direction()
{
if(directions.empty()) {
return -1;
}
float dir = directions[next_step];
if(!reverse) {
if(next_step < directions.size() - 1) {
next_step++;
} else {
reverse = true;
}
} else {
if (dir >= 180) {
dir -= 180;
} else {
dir += 180;
}
if(next_step > 0) {
next_step--;
} else {
reverse = false;
}
}
return dir;
}
}
\ No newline at end of file
#pragma once
#include <mirrage/ecs/ecs.hpp>
#include <vector>
namespace phase_shifter::gameplay {
struct Fixed_path_comp : public mirrage::ecs::Component<Fixed_path_comp> {
static constexpr const char* name() { return "FixedPath"; }
using Component::Component;
void update_path(std::vector<float> directions);
float next_direction();
private:
int next_step = 0; //index of the next step
std::vector<float> directions; //vector containing the steps as angles (degrees) with 0 being North (-Z)
bool reverse = false; //flag wether the path is now traced backwards
};
}
\ No newline at end of file
...@@ -9,11 +9,11 @@ namespace phase_shifter::gameplay { ...@@ -9,11 +9,11 @@ namespace phase_shifter::gameplay {
static constexpr const char* name() { return "Spring"; } static constexpr const char* name() { return "Spring"; }
using Component::Component; using Component::Component;
glm::vec3 velocity = {0.f, 0.f, 0.f};
float spring_constant = 1.f; float spring_constant = 1.f;
float mass = 1.f; float mass = 1.f;
glm::vec3 velocity = {0.f, 0.f, 0.f};
}; };
sf2_structDef(Spring_comp, spring_constant); sf2_structDef(Spring_comp, spring_constant, mass);
} }
\ No newline at end of file
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "gameplay/beat_system.hpp" #include "gameplay/beat_system.hpp"
#include "gameplay/movement_system.hpp" #include "gameplay/movement_system.hpp"
#include "gameplay/camera_system.hpp" #include "gameplay/camera_system.hpp"
#include "gameplay/enemy_system.hpp"
#include "helper/attachment_system.hpp" #include "helper/attachment_system.hpp"
#include "input/input_system.hpp" #include "input/input_system.hpp"
#include "ui/hud_system.hpp" #include "ui/hud_system.hpp"
...@@ -30,6 +31,7 @@ namespace phase_shifter { ...@@ -30,6 +31,7 @@ namespace phase_shifter {
, _beat_system(std::make_unique<gameplay::Beat_system>()) , _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>(_entities, *_beat_system))
, _camera_system(std::make_unique<gameplay::Camera_system>(_entities)) , _camera_system(std::make_unique<gameplay::Camera_system>(_entities))
, _enemy_system(std::make_unique<gameplay::Enemy_system>(_entities))
, _input_system(std::make_unique<input::Input_system>(engine.bus(), _entities)) , _input_system(std::make_unique<input::Input_system>(engine.bus(), _entities))
, _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)) , _hud_system(std::make_unique<ui::Hud_system>(engine.gui(), _entities))
...@@ -116,6 +118,16 @@ namespace phase_shifter { ...@@ -116,6 +118,16 @@ namespace phase_shifter {
}); });
}) })
.create(); .create();
entities()
.entity_builder("basic_enemy")
.position({3, 0, 0})
.post_create([=](ecs::Entity_facet entity) {
entity.process<gameplay::Fixed_path_comp>([&](auto& path) {
path.update_path({90.f, 180.f, 90.f});
});
})
.create();
} }
Meta_system::~Meta_system() Meta_system::~Meta_system()
...@@ -132,6 +144,7 @@ namespace phase_shifter { ...@@ -132,6 +144,7 @@ namespace phase_shifter {
_input_system->update(dt); _input_system->update(dt);
_movement_system->update(dt); _movement_system->update(dt);
_camera_system->update(dt); _camera_system->update(dt);
_enemy_system->update(dt);
_attachment_system->update(dt); _attachment_system->update(dt);
......
...@@ -23,6 +23,7 @@ namespace phase_shifter { ...@@ -23,6 +23,7 @@ namespace phase_shifter {
class Beat_system; class Beat_system;
class Movement_system; class Movement_system;
class Camera_system; class Camera_system;
class Enemy_system;
} // namespace gameplay } // namespace gameplay
namespace helper { namespace helper {
class Attachment_system; class Attachment_system;
...@@ -62,6 +63,7 @@ namespace phase_shifter { ...@@ -62,6 +63,7 @@ namespace phase_shifter {
std::unique_ptr<helper::Attachment_system> _attachment_system; std::unique_ptr<helper::Attachment_system> _attachment_system;
std::unique_ptr<ui::Hud_system> _hud_system; std::unique_ptr<ui::Hud_system> _hud_system;
std::unique_ptr<gameplay::Camera_system> _camera_system; std::unique_ptr<gameplay::Camera_system> _camera_system;
std::unique_ptr<gameplay::Enemy_system> _enemy_system;
// TODO: add systems here // TODO: add systems here
mirrage::util::Console_command_container _commands; 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