Skip to content

Commit

Permalink
ECS: Modif collision system to look better
Browse files Browse the repository at this point in the history
PATCH
  • Loading branch information
KitetsuK committed Sep 29, 2023
1 parent b7ea845 commit 30584b6
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/ECS/Systems/Systems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,35 @@ namespace Systems {
Registry::getInstance()
.getComponents<Types::Dammage>()[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<std::optional<Types::CollisionRect>>::iterator collisionIt,
std::vector<std::optional<Types::Position>>::iterator positionIt,
Registry::components<Types::Position> arrPosition,
Registry::components<Types::CollisionRect> arrCollision
std::vector<std::optional<Types::CollisionRect>>::iterator &collisionIt,
std::vector<std::optional<Types::Position>>::iterator &positionIt,
Registry::components<Types::Position> &arrPosition,
Registry::components<Types::CollisionRect> &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
Expand All @@ -97,11 +103,6 @@ namespace Systems {
giveDamages(
std::distance(arrPosition.begin(), positionIt),
std::distance(arrPosition.begin(), tmpPositionIt));
tmpCollisionIt++;
tmpPositionIt++;
} else {
tmpCollisionIt++;
tmpPositionIt++;
}
}
}
Expand All @@ -125,9 +126,9 @@ namespace Systems {
positionIt,
arrPosition,
arrCollisionRect);
collisionIt++;
positionIt++;
}
collisionIt++;
positionIt++;
}
}

Expand Down

0 comments on commit 30584b6

Please sign in to comment.