diff --git a/assets/game_assets/blueprints/basic_enemy.json b/assets/game_assets/blueprints/basic_enemy.json index 820f875fd8cb9590dab3dc9b8b22fcb0915bb77a..3e46ad1ab79ed19b32a548d11aa9083c9f26977b 100644 --- a/assets/game_assets/blueprints/basic_enemy.json +++ b/assets/game_assets/blueprints/basic_enemy.json @@ -17,6 +17,8 @@ "step_time_percentage": 0.2, "off_beat_threshold": 0.2 }, + "Killable": { + }, "FixedPath": { } } diff --git a/assets/game_assets/blueprints/hunting_enemy.json b/assets/game_assets/blueprints/hunting_enemy.json index 621b719a5e64c0ec817f883a907b8b3e8be223ee..b3aec0a75265674c5d4e98dee7e4c2b3950bb61a 100644 --- a/assets/game_assets/blueprints/hunting_enemy.json +++ b/assets/game_assets/blueprints/hunting_enemy.json @@ -18,5 +18,7 @@ "off_beat_threshold": 0.2 }, "FollowTarget": { + }, + "Killable": { } } diff --git a/assets/game_assets/blueprints/player.json b/assets/game_assets/blueprints/player.json index 99b33fa140528033b056ff13226f2954db171380..868f992a4a42fa12955f026d5cfd7a438ae4e066 100644 --- a/assets/game_assets/blueprints/player.json +++ b/assets/game_assets/blueprints/player.json @@ -19,6 +19,9 @@ }, "Input_controller": {}, "Player": {}, + "Dash": { + "attack_width": 0.8 + }, "Rigid_body": { "radius": 1.0 } diff --git a/src/gameplay/dash_comp.cpp b/src/gameplay/dash_comp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3908269a939402377145ff4f64ec0be17053c615 --- /dev/null +++ b/src/gameplay/dash_comp.cpp @@ -0,0 +1 @@ +#include "dash_comp.hpp" \ No newline at end of file diff --git a/src/gameplay/dash_comp.hpp b/src/gameplay/dash_comp.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ede545ee82ab08542a7ee4a5c3e26c395e46e6e4 --- /dev/null +++ b/src/gameplay/dash_comp.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include + + +namespace phase_shifter::gameplay { + struct Dash_comp : public mirrage::ecs::Component { + static constexpr const char* name() { return "Dash"; } + using Component::Component; + + float attack_width = 1; + bool was_move = false; + bool dash = false; + glm::vec2 last_position; + }; + + sf2_structDef(Dash_comp, attack_width, was_move, dash, last_position); +} \ No newline at end of file diff --git a/src/gameplay/dash_system.cpp b/src/gameplay/dash_system.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3426e957cba11f0c71232a872cf291363f3e7593 --- /dev/null +++ b/src/gameplay/dash_system.cpp @@ -0,0 +1,108 @@ +#include "dash_system.hpp" +#include "dash_comp.hpp" +#include "killable_comp.hpp" +#include "movement_comp.hpp" + +#include +#include +#include + +namespace phase_shifter::gameplay { + + bool rect_circle_intersects(float rect_x, + float rect_y, + float rect_w, + float rect_h, + float circle_x, + float circle_y, + float radius) + { + float dist_x = std::abs(circle_x - rect_x - rect_w / 2); + float dist_y = std::abs(circle_y - rect_y - rect_h / 2); + + if(dist_x > rect_w / 2 + radius) { + return false; + } + if(dist_y > rect_h / 2 + radius) { + return false; + } + + if(dist_x <= rect_w / 2) { + return true; + } + if(dist_y <= rect_h / 2) { + return true; + } + + float dx = dist_x - rect_w / 2; + float dy = dist_y - rect_h / 2; + return dx * dx + dy * dy <= radius * radius; + } + + glm::vec2 rotate_point(glm::vec2 p, float angle) + { + return {p.x * std::cos(angle) - p.y * std::sin(angle), p.y * std::cos(angle) + p.x * std::sin(angle)}; + } + + + using mirrage::ecs::Entity_handle; + using mirrage::ecs::components::Transform_comp; + + Dash_system::Dash_system(mirrage::ecs::Entity_manager& ecs) : _ecs(ecs) + { + _ecs.register_component_type(); + _ecs.register_component_type(); + } + + void Dash_system::update(mirrage::util::Time dt) + { + + for(auto&& [transform, move, dash] : _ecs.list()) { + if((dash.dash || dash.was_move) && move.step_time_left > 0) { + //dash + glm::vec2 position(transform.position.x, transform.position.z); + auto movement = position - dash.last_position; + auto angle = std::atan2(movement.y, movement.x); + auto width = glm::length(movement); + auto height = dash.attack_width; + + auto center = rotate_point( + {dash.last_position.x + movement.x / 2, dash.last_position.y + movement.y / 2}, + angle); + glm::vec2 topleft(center.x - width / 2, center.y + height / 2); + + std::cout << angle * 180 / 3.14 << std::endl; + + for(auto&& [entity, k_transform, kill] : + _ecs.list()) { + auto circle = rotate_point({k_transform.position.x, k_transform.position.z}, angle); + if(rect_circle_intersects( + topleft.x, + topleft.y, + width, + height, + circle.x, + circle.y, + 1)) + { + _ecs.erase(entity); + } + } + + dash.last_position = position; + dash.dash = true; + } else { + dash.dash = false; + } + + if(move.move) { + if(!dash.was_move || move.step_time_left <= 0) { + dash.was_move = true; + dash.last_position = {transform.position.x, transform.position.z}; + } + } else { + dash.was_move = false; + } + } + } +} // namespace phase_shifter::gameplay \ No newline at end of file diff --git a/src/gameplay/dash_system.hpp b/src/gameplay/dash_system.hpp new file mode 100644 index 0000000000000000000000000000000000000000..594e4f406ff3df316d6b6738d8aa0ccc62a748be --- /dev/null +++ b/src/gameplay/dash_system.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include + +namespace mirrage::ecs { + class Entity_manager; +} + +namespace phase_shifter::gameplay { + + class Dash_system { + public: + Dash_system(mirrage::ecs::Entity_manager&); + + void update(mirrage::util::Time); + + private: + mirrage::ecs::Entity_manager& _ecs; + bool _was_move = false; + glm::vec2 _start_position; + }; + +} \ No newline at end of file diff --git a/src/gameplay/killable_comp.cpp b/src/gameplay/killable_comp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/gameplay/killable_comp.hpp b/src/gameplay/killable_comp.hpp new file mode 100644 index 0000000000000000000000000000000000000000..848eb3ade30c760568cccf6245499540ab3bea74 --- /dev/null +++ b/src/gameplay/killable_comp.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include +#include +#include + + +namespace phase_shifter::gameplay { + + struct Killable_comp : public mirrage::ecs::Stateless_tag_component { + static constexpr const char* name() { return "Killable"; } + using Stateless_tag_component::Stateless_tag_component; + }; + +} // namespace phase_shifter::gameplay diff --git a/src/gameplay/movement_system.cpp b/src/gameplay/movement_system.cpp index 483865bf01cb0b13f2779a1d9d91059cfd6fb5f8..eb96892ac6b64deb4fd35c608ffd5373cfd77b26 100644 --- a/src/gameplay/movement_system.cpp +++ b/src/gameplay/movement_system.cpp @@ -20,9 +20,9 @@ namespace phase_shifter::gameplay { auto o = [](auto t, auto s) { return t * t * ((s + 1) * t + s); }; if(t < 0.5) - return 0.5 * a(t * 2.0, tension); + return 0.5f * a(t * 2.0f, tension); else - return 0.5 * (o(t * 2.0 - 2.0, tension) + 2.0); + return 0.5f * (o(t * 2.0f - 2.0f, tension) + 2.0f); } } // namespace diff --git a/src/meta_system.cpp b/src/meta_system.cpp index 8ad5724478920670a5df79b238b6a77f49fc75b2..e82c962f13ada6ddd8ae9e16952b55d83c2b3cda 100644 --- a/src/meta_system.cpp +++ b/src/meta_system.cpp @@ -10,6 +10,8 @@ #include "helper/attachment_system.hpp" #include "input/input_system.hpp" #include "level/level_system.hpp" +#include "gameplay/killable_comp.hpp" +#include "gameplay/dash_system.hpp" #include "ui/hud_system.hpp" #include @@ -39,6 +41,7 @@ namespace phase_shifter { , _level_system(std::make_unique(_entities, engine.assets())) , _camera_system(std::make_unique(_entities)) , _enemy_system(std::make_unique(_entities)) + , _dash_system(std::make_unique(_entities)) { _entities.register_component_type(); @@ -111,6 +114,7 @@ namespace phase_shifter { _beat_system->update(dt); _input_system->update(dt); _level_system->update(dt); + _dash_system->update(dt); _movement_system->update(dt); _combat_system->update(dt); _camera_system->update(dt); diff --git a/src/meta_system.hpp b/src/meta_system.hpp index 99a831d348de365ad1ac7ef8f771fab3474b79b5..d4cddc553db71af5cee7c9ac6676c1b8e33197fb 100644 --- a/src/meta_system.hpp +++ b/src/meta_system.hpp @@ -25,6 +25,7 @@ namespace phase_shifter { class Camera_system; class Enemy_system; class Combat_system; + class Dash_system; } // namespace gameplay namespace helper { class Attachment_system; @@ -71,6 +72,7 @@ namespace phase_shifter { std::unique_ptr _level_system; std::unique_ptr _camera_system; std::unique_ptr _enemy_system; + std::unique_ptr _dash_system; // TODO: add systems here mirrage::util::Console_command_container _commands;