-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from X-R-G-B/feature/RB-56-checkDeads
Feature/rb 56 check deads
- Loading branch information
Showing
8 changed files
with
171 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** R-Bus | ||
** File description: | ||
** Death systems implementation | ||
*/ | ||
|
||
#include "DeathSystems.hpp" | ||
#include <optional> | ||
#include <unordered_map> | ||
#include "CustomTypes.hpp" | ||
#include "Registry.hpp" | ||
|
||
namespace Systems { | ||
|
||
const std::function<void(std::size_t)> setPlayerAnimRectDeath = | ||
[](std::size_t id) { | ||
Registry::components<Types::AnimRect> arrAnimRect = | ||
Registry::getInstance().getComponents<Types::AnimRect>(); | ||
|
||
if (arrAnimRect.exist(id)) { | ||
Types::AnimRect& anim = arrAnimRect[id]; | ||
if (anim.currentRectList != Types::RectListType::DEAD) { | ||
anim.changeRectList(Types::RectListType::DEAD); | ||
} | ||
} | ||
}; | ||
|
||
const std::function<void(std::size_t)> setEnemyDeathFunc = | ||
[](std::size_t id) { | ||
Registry::getInstance().removeEntity(id); | ||
}; | ||
|
||
// MAP FOR DEATH FUNCTIONS FOR EACH ENTITY | ||
const std::unordered_map<std::type_index, std::function<void(std::size_t)>> | ||
deathFunctions = { | ||
{std::type_index(typeid(Types::Player)), setPlayerAnimRectDeath}, | ||
{std::type_index(typeid(Types::Enemy)), setEnemyDeathFunc }, | ||
}; | ||
|
||
void DeathSystems::setEntityDeathFunction( | ||
std::size_t /*unused*/, | ||
std::size_t /*unused*/) | ||
{ | ||
Registry::components<Types::Dead> arrDead = | ||
Registry::getInstance().getComponents<Types::Dead>(); | ||
|
||
std::vector<std::size_t> ids = arrDead.getExistingsId(); | ||
|
||
for (const auto& [typeIndex, function] : deathFunctions) { | ||
std::vector<std::size_t> entities = | ||
Registry::getInstance().getEntitiesByComponents({typeIndex}); | ||
for (std::size_t id : entities) { | ||
if (arrDead.exist(id) | ||
&& arrDead[id].deathFunction == std::nullopt) { | ||
arrDead[id].deathFunction = function; | ||
} | ||
} | ||
} | ||
} | ||
|
||
std::vector<std::function<void(std::size_t, std::size_t)>> | ||
DeathSystems::getDeathSystems() | ||
{ | ||
return {setEntityDeathFunction}; | ||
} | ||
} // namespace Systems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** R-Bus | ||
** File description: | ||
** DeathSystems | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <vector> | ||
|
||
namespace Systems { | ||
namespace DeathSystems { | ||
std::vector<std::function<void(std::size_t, std::size_t)>> | ||
getDeathSystems(); | ||
void setEntityDeathFunction( | ||
std::size_t /*unused*/, | ||
std::size_t /*unused*/); | ||
} // namespace DeathSystems | ||
} // namespace Systems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters