diff --git a/src/Client/Systems/Events/EventsSystems.cpp b/src/Client/Systems/Events/EventsSystems.cpp index c8375852..27c65020 100644 --- a/src/Client/Systems/Events/EventsSystems.cpp +++ b/src/Client/Systems/Events/EventsSystems.cpp @@ -57,56 +57,60 @@ namespace Systems { const Types::Rect spriteRect = {300, 121, 32, 10}; const std::string bulletPath = "assets/R-TypeSheet/r-typesheet1.gif"; - constexpr float playerWidth = 5.0F; - constexpr float playerHeight = 5.0F; + constexpr float bulletWidth = 5.0F; + constexpr float bulletHeight = 5.0F; const Types::CollisionRect collisionRect = {1, 1}; const Types::Velocity velocity = {-0.7F, 0.0F}; - const Types::Missiles missileType = {"classic"}; + const Types::Missiles missileType = {Types::MissileTypes::CLASSIC}; const Types::Health health = {1}; const Types::Dammage dammage = {10}; + static void createMissile(std::size_t id, Registry::components &arrPosition) + { + if (arrPosition.exist(id)) { + std::size_t entityId = Registry::getInstance().addEntity(); + + Registry::getInstance() + .getComponents() + .insertBack({arrPosition[id].x, arrPosition[id].y}); + Registry::getInstance() + .getComponents() + .insertBack( + {bulletPath, bulletWidth, bulletHeight, entityId}); + Registry::getInstance() + .getComponents() + .insertBack(spriteRect); + Registry::getInstance() + .getComponents() + .insertBack(collisionRect); + Registry::getInstance() + .getComponents() + .insertBack(missileType); + Registry::getInstance() + .getComponents() + .insertBack(velocity); + Registry::getInstance() + .getComponents() + .insertBack(health); + Registry::getInstance() + .getComponents() + .insertBack(dammage); + Registry::getInstance().setToFrontLayers(entityId); + } + } + void playerShootBullet(std::size_t, std::size_t) { Registry::components arrPlayer = Registry::getInstance().getComponents(); Registry::components arrPosition = Registry::getInstance().getComponents(); - Registry::components arrRect = - Registry::getInstance().getComponents(); std::vector ids = arrPlayer.getExistingsId(); if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_SPACE)) { for (auto &id : ids) { - if (arrPosition.exist(id) && arrRect.exist(id)) { - std::size_t entityId = Registry::getInstance().addEntity(); - Registry::getInstance() - .getComponents() - .insertBack({arrPosition[id].x, arrPosition[id].y}); - Registry::getInstance() - .getComponents() - .insertBack( - {bulletPath, playerWidth, playerHeight, entityId}); - Registry::getInstance() - .getComponents() - .insertBack(spriteRect); - Registry::getInstance() - .getComponents() - .insertBack(collisionRect); - Registry::getInstance() - .getComponents() - .insertBack(missileType); - Registry::getInstance() - .getComponents() - .insertBack(velocity); - Registry::getInstance() - .getComponents() - .insertBack(health); - Registry::getInstance() - .getComponents() - .insertBack(dammage); - Registry::getInstance().setToFrontLayers(entityId); - } + createMissile(id, arrPosition); } } } diff --git a/src/ECS/ECSCustomTypes.hpp b/src/ECS/ECSCustomTypes.hpp index 9da6ba54..9f0e80b0 100644 --- a/src/ECS/ECSCustomTypes.hpp +++ b/src/ECS/ECSCustomTypes.hpp @@ -11,6 +11,9 @@ namespace Types { + enum MissileTypes {CLASSIC}; + + struct CollisionRect { float width; float height; @@ -43,7 +46,7 @@ namespace Types { struct Missiles { // maybe enum better ? - std::string type; + MissileTypes type; }; } // namespace Types diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 7aa196ab..48591102 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -119,8 +119,8 @@ namespace Systems { .getComponents() .insert( id, - {arrCollisionRect[id].width + 2, - arrCollisionRect[id].height + 2}); + {arrCollisionRect[id].width , + arrCollisionRect[id].height}); } } }