Commit d629454d authored by Tim Scheiber's avatar Tim Scheiber
Browse files

Added shooting with bullet patterns

parent 749a779b
Pipeline #3277 passed with stage
in 2 minutes and 44 seconds
......@@ -17,6 +17,9 @@
"step_time_percentage": 0.2,
"off_beat_threshold": 0.2
},
"FixedPath": {
}
"FixedPath": {
},
"Shooting": {
"orientation": 270
}
}
{
"Transform": {
"scale": {
"x": 0.3,
"y": 0.3,
"z": 0.3
"x": 0.2,
"y": 0.2,
"z": 0.2
}
},
"Model": {
......@@ -19,6 +19,6 @@
},
"ContinuousPath": {
"direction": 270,
"curvature": 0,
"curvature": 0
}
}
#include "enemy_system.hpp"
#include "beat_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)
Enemy_system::Enemy_system(mirrage::ecs::Entity_manager& entity_manager, const Beat_system& beat_system)
: _entity_manager(entity_manager), _beat_system(beat_system)
{
_entity_manager.register_component_type<Fixed_path_comp>();
_entity_manager.register_component_type<Follow_target_comp>();
_entity_manager.register_component_type<Continuous_path_comp>();
_entity_manager.register_component_type<Shooting_comp>();
}
void Enemy_system::update(mirrage::util::Time dt)
{
auto beat = _beat_system.beat_state();
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;
......@@ -48,5 +54,24 @@ namespace phase_shifter::gameplay {
movement.move = true;
}
}
for (auto&& [shooting, transform] : _entity_manager.list<Shooting_comp, mirrage::ecs::components::Transform_comp>()) {
if (beat.beat) {
auto bullet_pattern = shooting.next_pattern();
auto orientation = shooting.orientation;
for (auto bullet : bullet_pattern.bullets) {
_entity_manager.entity_builder("bullet")
.position(transform.position)
.post_create([=](auto entity) {
entity.process([=](Continuous_path_comp& cont_path) {
cont_path.direction = orientation + bullet.direction;
cont_path.curvature = bullet.curvature;
});
})
.create();
}
}
}
}
}
\ No newline at end of file
......@@ -6,15 +6,20 @@
#include "fixed_path_comp.hpp"
#include "follow_target_comp.hpp"
#include "continuous_path_comp.hpp"
#include "shooting_comp.hpp"
namespace phase_shifter::gameplay {
class Beat_system;
class Enemy_system {
public:
Enemy_system(mirrage::ecs::Entity_manager& entity_manager);
Enemy_system(mirrage::ecs::Entity_manager& entity_manager, const Beat_system& beat_system);
void update(mirrage::util::Time dt);
private:
mirrage::ecs::Entity_manager& _entity_manager;
const Beat_system& _beat_system;
};
}
\ No newline at end of file
......@@ -4,9 +4,17 @@ namespace phase_shifter::gameplay {
void Fixed_path_comp::update_path(std::vector<float> directions)
{
next_step = 0;
reverse = false;
next_step = 0;
reverse = false;
this->directions = directions;
for (float angle : this->directions) {
while (angle < 0) {
angle += 360;
}
while (angle >= 360) {
angle -= 360;
}
}
}
float Fixed_path_comp::next_direction()
......
#include "shooting_comp.hpp"
namespace phase_shifter::gameplay {
Bulletpattern Shooting_comp::next_pattern() {
if (patterns.empty()) {
return Bulletpattern();
}
Bulletpattern pattern = patterns[i_next_pattern++];
i_next_pattern %= patterns.size();
return pattern;
}
}
\ No newline at end of file
#pragma once
#include <mirrage/ecs/ecs.hpp>
#include <vector>
#include <array>
namespace phase_shifter::gameplay {
struct Bullet {
Bullet() {}
Bullet(float direction, float curvature) : direction(direction), curvature(curvature) {}
Bullet(float attributes[2]) : direction(attributes[0]), curvature(attributes[1]) {}
float direction = 0;
float curvature = 0;
};
struct Bulletpattern {
Bulletpattern() {}
Bulletpattern(std::vector<Bullet> bullets) : bullets(bullets) {}
std::vector<Bullet> bullets;
};
struct Shooting_comp : public mirrage::ecs::Component<Shooting_comp> {
static constexpr const char* name() { return "Shooting"; }
using Component::Component;
Bulletpattern next_pattern();
float orientation = 0; // orientation of "forward" in degrees with 0 beeing North (-Z)
std::vector<Bulletpattern> patterns; // sequence of bullet patterns that are looped through
private:
unsigned int i_next_pattern = 0;
};
sf2_structDef(Shooting_comp, orientation);
}
\ No newline at end of file
......@@ -38,7 +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))
, _enemy_system(std::make_unique<gameplay::Enemy_system>(_entities, *_beat_system))
{
_entities.register_component_type<ecs::components::Transform_comp>();
......@@ -94,6 +94,18 @@ namespace phase_shifter {
.create();
_level_system->load("dummy");
entities()
.entity_builder("basic_enemy")
.position({20, 0, 15})
.post_create([=](auto entity) {
entity.process([&](gameplay::Fixed_path_comp& fixed_path) { fixed_path.update_path({}); });
entity.process([&](gameplay::Shooting_comp& shooting) {
shooting.patterns.push_back(gameplay::Bulletpattern({{0, 0}, {30, 0}, {-30, 0}}));
shooting.patterns.push_back(gameplay::Bulletpattern({{15, 0}, {-15, 0}}));
});
})
.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