From 1a687852cbaa74c1326d89b173ad85b9bd85b41b Mon Sep 17 00:00:00 2001 From: tenshi Date: Tue, 24 Oct 2023 10:51:53 +0200 Subject: [PATCH 1/3] GAME-LOGIC: Fix bullet pos PATCH --- src/Client/Systems/Events/EventsSystems.cpp | 21 +++++++++++++++++++-- src/ECS/Systems/BulletsSystems.cpp | 13 ++----------- src/ECS/Systems/Systems.hpp | 1 + 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Client/Systems/Events/EventsSystems.cpp b/src/Client/Systems/Events/EventsSystems.cpp index e0c59da0..8c7d905f 100644 --- a/src/Client/Systems/Events/EventsSystems.cpp +++ b/src/Client/Systems/Events/EventsSystems.cpp @@ -99,6 +99,22 @@ namespace Systems { } } + static Types::Position adjustMissilePosition(Types::Position &pos, missileTypes_e typeOfMissile, std::size_t id) + { + adjustPlayerBulletPosition(pos, id); + Json &json = Json::getInstance(); + Registry::getInstance().addEntity(); + nlohmann::json bulletData = + json.getJsonObjectById(JsonType::BULLETS, getMissileId(typeOfMissile), "bullets"); + Types::CollisionRect collisionRect = + json.getDataFromJson(bulletData, "collisionRect"); + Types::Position newPos = pos; + int halfSprite = Maths::divisionWithTwoIntDecimals(collisionRect.width, 200); + newPos.y = Maths::subtractionWithTwoIntDecimals(newPos.y, halfSprite); + newPos.x = pos.x; + return newPos; + } + void playerShootBullet(std::size_t /*unused*/, std::size_t /*unused*/) { std::lock_guard lock(Registry::getInstance().mutex); @@ -119,10 +135,11 @@ namespace Systems { if (arrHealth.exist(id) && arrHealth[id].hp <= 0) { continue; } + Types::Position pos = adjustMissilePosition(arrPosition[id], missile.type, id); Nitwork::NitworkClient::getInstance().addNewBulletMsg( - {Maths::removeIntDecimals(arrPosition[id].x), Maths::removeIntDecimals(arrPosition[id].y)}, + {Maths::removeIntDecimals(pos.x), Maths::removeIntDecimals(pos.y)}, missile.type); - createMissile(adjustPlayerBulletPosition(arrPosition[id], id), missile); + createMissile(pos, missile); clock_.restart(getClockIdFromMissileType(missile.type)); } } diff --git a/src/ECS/Systems/BulletsSystems.cpp b/src/ECS/Systems/BulletsSystems.cpp index 24b01f6c..37869f49 100644 --- a/src/ECS/Systems/BulletsSystems.cpp +++ b/src/ECS/Systems/BulletsSystems.cpp @@ -32,7 +32,7 @@ namespace Systems { {PERFORANT, "perforant"} }; - static std::string getMissileId(missileTypes_e type) + std::string getMissileId(missileTypes_e type) { auto it = missileTypeMap.find(type); if (it != missileTypeMap.end()) { @@ -61,15 +61,6 @@ namespace Systems { } #endif - static Types::Position adjustMissilePosition(Types::Position &pos, Types::CollisionRect &collisionRect) - { - Types::Position newPos = pos; - int halfSprite = Maths::divisionWithTwoIntDecimals(collisionRect.width, 200); - newPos.y = Maths::subtractionWithTwoIntDecimals(newPos.y, halfSprite); - newPos.x = pos.x; - return newPos; - } - #ifdef CLIENT static void addSpriteRectsForBullet(nlohmann::json &bulletData, Types::CollisionRect &collisionRect) { @@ -124,7 +115,7 @@ namespace Systems { Types::Missiles missileType = typeOfMissile; Types::Dead deadComp = {}; Types::PlayerAllies playerAlliesComp = {}; - Types::Position position = adjustMissilePosition(pos, collisionRect); + Types::Position position = pos; struct health_s healthComp = {json.getDataFromJson(bulletData, "health")}; Types::Damage damageComp = {json.getDataFromJson(bulletData, "damage")}; diff --git a/src/ECS/Systems/Systems.hpp b/src/ECS/Systems/Systems.hpp index d76120de..28e7d81d 100644 --- a/src/ECS/Systems/Systems.hpp +++ b/src/ECS/Systems/Systems.hpp @@ -28,6 +28,7 @@ namespace Systems { void entitiesCollision(std::size_t, std::size_t); void deathChecker(std::size_t, std::size_t); void updatePhysics(std::size_t, std::size_t); + std::string getMissileId(missileTypes_e type); void initWave(std::size_t managerId, std::size_t systemId); void initPlayer( unsigned int constId, From 4a9f16565b2345eb4e13d5c65eccf574c7689c0c Mon Sep 17 00:00:00 2001 From: tenshi Date: Tue, 24 Oct 2023 11:04:02 +0200 Subject: [PATCH 2/3] GAME-LOGIC: Fix event system file --- src/Client/Systems/Events/EventsSystems.cpp | 22 ++++++++------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/Client/Systems/Events/EventsSystems.cpp b/src/Client/Systems/Events/EventsSystems.cpp index 8c7d905f..06ed98af 100644 --- a/src/Client/Systems/Events/EventsSystems.cpp +++ b/src/Client/Systems/Events/EventsSystems.cpp @@ -82,33 +82,27 @@ namespace Systems { return true; } - static Types::Position adjustPlayerBulletPosition(Types::Position &playerPos, std::size_t id) + static Types::Position + adjustMissilePosition(Types::Position &pos, missileTypes_e typeOfMissile, std::size_t id) { + Types::Position newPos = pos; + Json &json = Json::getInstance(); Registry ®istry = Registry::getInstance(); Registry::components arrCol = registry.getComponents(); if (arrCol.exist(id)) { Types::CollisionRect &col = arrCol[id]; - float posX = Maths::intToFloatConservingDecimals(playerPos.x) + float posX = Maths::intToFloatConservingDecimals(pos.x) + (Maths::intToFloatConservingDecimals(col.width) / 2.F); - float posY = Maths::intToFloatConservingDecimals(playerPos.y) + float posY = Maths::intToFloatConservingDecimals(pos.y) + (Maths::intToFloatConservingDecimals(col.height) / 2.F); - return {Maths::floatToIntConservingDecimals(posX), Maths::floatToIntConservingDecimals(posY)}; - } else { - return {playerPos.x, playerPos.y}; + newPos.x = Maths::floatToIntConservingDecimals(posX); + newPos.y = Maths::floatToIntConservingDecimals(posY); } - } - - static Types::Position adjustMissilePosition(Types::Position &pos, missileTypes_e typeOfMissile, std::size_t id) - { - adjustPlayerBulletPosition(pos, id); - Json &json = Json::getInstance(); - Registry::getInstance().addEntity(); nlohmann::json bulletData = json.getJsonObjectById(JsonType::BULLETS, getMissileId(typeOfMissile), "bullets"); Types::CollisionRect collisionRect = json.getDataFromJson(bulletData, "collisionRect"); - Types::Position newPos = pos; int halfSprite = Maths::divisionWithTwoIntDecimals(collisionRect.width, 200); newPos.y = Maths::subtractionWithTwoIntDecimals(newPos.y, halfSprite); newPos.x = pos.x; From 54e5d527560c784aeae0e0945cb5419dee314699 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Tue, 24 Oct 2023 09:06:14 +0000 Subject: [PATCH 3/3] FORMAT-AUTO: automatic format on pull request #127 --- src/Client/Systems/Events/EventsSystems.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Client/Systems/Events/EventsSystems.cpp b/src/Client/Systems/Events/EventsSystems.cpp index 06ed98af..17a9106b 100644 --- a/src/Client/Systems/Events/EventsSystems.cpp +++ b/src/Client/Systems/Events/EventsSystems.cpp @@ -103,9 +103,9 @@ namespace Systems { json.getJsonObjectById(JsonType::BULLETS, getMissileId(typeOfMissile), "bullets"); Types::CollisionRect collisionRect = json.getDataFromJson(bulletData, "collisionRect"); - int halfSprite = Maths::divisionWithTwoIntDecimals(collisionRect.width, 200); - newPos.y = Maths::subtractionWithTwoIntDecimals(newPos.y, halfSprite); - newPos.x = pos.x; + int halfSprite = Maths::divisionWithTwoIntDecimals(collisionRect.width, 200); + newPos.y = Maths::subtractionWithTwoIntDecimals(newPos.y, halfSprite); + newPos.x = pos.x; return newPos; }