From 30584b6a522ba5fa1b7c998d51bc92e052046146 Mon Sep 17 00:00:00 2001 From: Kitetsu Date: Fri, 29 Sep 2023 12:40:54 +0200 Subject: [PATCH] ECS: Modif collision system to look better PATCH --- src/ECS/Systems/Systems.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 775a567c..367bc75c 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -62,29 +62,35 @@ namespace Systems { Registry::getInstance() .getComponents()[secondEntity]; - if (firstEntityDammage.has_value() && secondEntityHealth.has_value()) { - secondEntityHealth->hp -= firstEntityDammage->dammage; + if (firstEntityDammage.has_value() && secondEntityHealth.has_value() + && secondEntityHealth->hp > 0 && firstEntityDammage->dammage > 0) { + if (firstEntityHealth->hp != 0) { + secondEntityHealth->hp -= firstEntityDammage->dammage; + } } - if (secondEntityDammage.has_value() && firstEntityHealth.has_value()) { - firstEntityHealth->hp -= secondEntityDammage->dammage; + if (secondEntityDammage.has_value() && firstEntityHealth.has_value() + && secondEntityHealth->hp > 0 && firstEntityHealth->hp > 0) { + if (secondEntityHealth->hp != 0) { + firstEntityHealth->hp -= secondEntityDammage->dammage; + } } } static void checkCollisionEntity( - std::vector>::iterator collisionIt, - std::vector>::iterator positionIt, - Registry::components arrPosition, - Registry::components arrCollision + std::vector>::iterator &collisionIt, + std::vector>::iterator &positionIt, + Registry::components &arrPosition, + Registry::components &arrCollision ) { auto tmpCollisionIt = collisionIt; auto tmpPositionIt = positionIt; - tmpPositionIt++; - tmpCollisionIt++; while (tmpCollisionIt != arrCollision.end() && tmpPositionIt != arrPosition.end()) { + tmpCollisionIt++; + tmpPositionIt++; if (tmpCollisionIt->has_value() && tmpPositionIt->has_value()) { if (positionIt->value().x < tmpPositionIt->value().x + tmpCollisionIt->value().width @@ -97,11 +103,6 @@ namespace Systems { giveDamages( std::distance(arrPosition.begin(), positionIt), std::distance(arrPosition.begin(), tmpPositionIt)); - tmpCollisionIt++; - tmpPositionIt++; - } else { - tmpCollisionIt++; - tmpPositionIt++; } } } @@ -125,9 +126,9 @@ namespace Systems { positionIt, arrPosition, arrCollisionRect); - collisionIt++; - positionIt++; } + collisionIt++; + positionIt++; } }