Commit 458744f8 authored by Florian Oetke's avatar Florian Oetke
Browse files

Merge remote-tracking branch 'origin/develop' into feature/3-smooth-movement

parents 7fc5aa65 749a779b
Pipeline #3262 passed with stage
in 2 minutes and 26 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": {
}
}
{
"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
},
"ContinuousPath": {
"direction": 270,
"curvature": 0,
}
}
{
"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
},
"FollowTarget": {
}
}
......@@ -11,7 +11,7 @@ namespace phase_shifter::gameplay {
float time_to_beat = 0.f;
float avg_beat_time = 1.f;
int beats_left = 999.f;
int beats_left = 999;
};
// TODO: replace placeholder logic with actual beat detection
......
#include "continuous_path_comp.hpp"
namespace phase_shifter::gameplay {
float Continuous_path_comp::next_direction() {
float dir = direction;
direction += curvature;
return dir;
}
}
\ No newline at end of file
#pragma once
#include <mirrage/ecs/ecs.hpp>
namespace phase_shifter::gameplay {
struct Continuous_path_comp : public mirrage::ecs::Component<Continuous_path_comp> {
static constexpr const char* name() { return "ContinuousPath"; }
using Component::Component;
float next_direction();
float direction = 0; // angle of direction with 0 beeing North (-Z)
float curvature = 0; // angle of curvature in degrees
};
sf2_structDef(Continuous_path_comp, direction, curvature);
} // namespace phase_shifter::gameplay
\ No newline at end of file
#include "enemy_system.hpp"
#include "movement_comp.hpp"
#include <mirrage/ecs/components/transform_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>();
_entity_manager.register_component_type<Follow_target_comp>();
_entity_manager.register_component_type<Continuous_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;
}
}
}
for (auto&&[movement, follow_target, transform] : _entity_manager.list<Movement_comp, Follow_target_comp, mirrage::ecs::components::Transform_comp>()) {
auto target_facet = _entity_manager.get(follow_target.target);
if(target_facet.is_some()) {
auto target_transform = target_facet.get_or_throw().get<mirrage::ecs::components::Transform_comp>();
if(target_transform.is_some()) {
auto& target_position = target_transform.get_or_throw().position;
auto& my_position = transform.position;
movement.aim = glm::vec2({target_position.x - my_position.x, target_position.z - my_position.z});
movement.move = true;
}
}
}
for(auto&& [movement, cont_path] : _entity_manager.list<Movement_comp, Continuous_path_comp>()) {
if(!movement.move) {
float rad_direction = cont_path.next_direction() * mirrage::util::PI / 180.f;
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"
#include "follow_target_comp.hpp"
#include "continuous_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:
unsigned 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
#pragma once
#include <mirrage/ecs/ecs.hpp>
namespace phase_shifter::gameplay {
struct Follow_target_comp : public mirrage::ecs::Component<Follow_target_comp> {
static constexpr const char* name() { return "FollowTarget"; }
using Component::Component;
mirrage::ecs::Entity_handle target;
};
} // namespace phase_shifter::gameplay
\ No newline at end of file
......@@ -9,10 +9,10 @@ namespace phase_shifter::gameplay {
static constexpr const char* name() { return "Spring"; }
using Component::Component;
glm::vec3 velocity = {0.f, 0.f, 0.f};
float spring_constant = 1.f;
float mass = 1.f;
glm::vec3 velocity = {0.f, 0.f, 0.f};
};
sf2_structDef(Spring_comp, spring_constant, mass);
......
......@@ -5,6 +5,7 @@
#include "gameplay/beat_system.hpp"
#include "gameplay/camera_system.hpp"
#include "gameplay/combat_system.hpp"
#include "gameplay/enemy_system.hpp"
#include "gameplay/movement_system.hpp"
#include "helper/attachment_system.hpp"
#include "input/input_system.hpp"
......@@ -37,6 +38,7 @@ namespace phase_shifter {
, _hud_system(std::make_unique<ui::Hud_system>(engine.gui(), _entities, *_beat_system))
, _level_system(std::make_unique<level::Level_system>(_entities, engine.assets()))
, _camera_system(std::make_unique<gameplay::Camera_system>(_entities))
, _enemy_system(std::make_unique<gameplay::Enemy_system>(_entities))
{
_entities.register_component_type<ecs::components::Transform_comp>();
......@@ -111,6 +113,7 @@ namespace phase_shifter {
_movement_system->update(dt);
_combat_system->update(dt);
_camera_system->update(dt);
_enemy_system->update(dt);
_attachment_system->update(dt);
......
......@@ -23,6 +23,7 @@ namespace phase_shifter {
class Beat_system;
class Movement_system;
class Camera_system;
class Enemy_system;
class Combat_system;
} // namespace gameplay
namespace helper {
......@@ -69,6 +70,7 @@ namespace phase_shifter {
std::unique_ptr<ui::Hud_system> _hud_system;
std::unique_ptr<level::Level_system> _level_system;
std::unique_ptr<gameplay::Camera_system> _camera_system;
std::unique_ptr<gameplay::Enemy_system> _enemy_system;
// TODO: add systems here
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