Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rb 63 basic ennemy #59

Merged
merged 16 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions assets/Json/ennemyData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"ennemy" : [
{
"spritePath": "assets/R-TypeSheet/r-typesheet20.gif",
"damage": 10.0,
"health": 1.0,
"width": 10.0,
"height": 10.0,
"position" : {
"x": 70.0,
"y": 50.0
},
"rect": {
"x": 18.0,
"y": 67.0,
"width": 31.0,
"height": 30
},
"collisionRect": {
"width": 10.0,
"height":10.0
},
"velocity": {
"speedX": -0.1,
"speedY": 0.0
},
"animRect": {
"move": [
{
"x": 18.0,
"y": 67.0,
"width": 31.0,
"height": 30.0
},
{
"x": 51.0,
"y": 67.0,
"width": 31.0,
"height": 30.0
},
{
"x": 85.0,
"y": 69.0,
"width": 30.0,
"height": 29.0
}
],
"attack": [],
"dead": []
}
}
]
}
8 changes: 4 additions & 4 deletions src/Client/Systems/Events/EventsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace Systems {
const Types::CollisionRect collisionRect = {1, 1};
const Types::Velocity velocity = {0.7F, 0.0F};
const Types::Missiles missileType = {Types::MissileTypes::CLASSIC};
const health_s health = {1};
const struct health_s health = {1};
const Types::Damage damage = {10};

static void createMissile(std::size_t id, Registry::components<Types::Position> &arrPosition)
Expand All @@ -88,14 +88,14 @@ namespace Systems {
Registry::getInstance().getComponents<Types::Missiles>().insertBack(missileType);
Registry::getInstance().getComponents<Types::PlayerAllies>().insertBack({});
Registry::getInstance().getComponents<Types::Velocity>().insertBack(velocity);
Registry::getInstance().getComponents<health_s>().insertBack(health);
Registry::getInstance().getComponents<struct health_s>().insertBack(health);
Registry::getInstance().getComponents<Types::Damage>().insertBack(damage);
Registry::getInstance().getComponents<Types::Dead>().insertBack({std::nullopt});
Registry::getInstance().setToFrontLayers(entityId);
}
}

const std::size_t waitTimeBullet = 1;
const std::size_t waitTimeBullet = 500;

void playerShootBullet(std::size_t /*unused*/, std::size_t /*unused*/)
{
Expand All @@ -108,7 +108,7 @@ namespace Systems {
std::vector<std::size_t> ids = arrPlayer.getExistingsId();

if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_SPACE)
&& clock_.elapsedSecondsSince(clockId) > waitTimeBullet) {
&& clock_.elapsedMillisecondsSince(clockId) > waitTimeBullet) {
clock_.restart(clockId);
for (auto &id : ids) {
createMissile(id, arrPosition);
Expand Down
5 changes: 0 additions & 5 deletions src/Client/Systems/Graphic/DeathSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ namespace Systems {
}
};

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*/)
Expand Down
10 changes: 4 additions & 6 deletions src/ECS/ECSCustomTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ namespace Types {
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Position, x, y);
};

struct InitialPosition {
float x;
float y;
};

struct Damage {
int damage;
};
Expand Down Expand Up @@ -75,7 +70,10 @@ namespace Types {

struct Enemy { };

struct Parallax { };
struct Parallax {
float x;
float y;
};

struct Dead {
Dead(std::optional<std::function<void(std::size_t id)>> func, std::size_t time = 0)
Expand Down
3 changes: 2 additions & 1 deletion src/ECS/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ void Registry::setToDefaultLayer(std::size_t id)

void Registry::setToFrontLayers(std::size_t id, FrontLayers layer)
{
_backLayers[layer].push_back(id);
removeFromDefaultLayer(id);
_frontLayers[layer].push_back(id);
}

std::vector<std::vector<std::size_t>> Registry::getBackLayers()
Expand Down
14 changes: 7 additions & 7 deletions src/ECS/SparseArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ class SparseArray {
}
std::size_t sparseValue = _sparse[id];
if (int(sparseValue) != -1) {
removeDenses(id, sparseValue);
removeDenses(sparseValue);
}
for (auto revIt2 = _revSparse.begin(); revIt2 != _revSparse.end(); revIt2++) {
if (*revIt2 > id) {
(*revIt2)--;
}
}
auto it = _sparse.begin();
std::advance(it, id);
Expand Down Expand Up @@ -95,19 +100,14 @@ class SparseArray {
}

private:
void removeDenses(std::size_t id, std::size_t sparseValue)
void removeDenses(std::size_t sparseValue)
{
auto it = _dense.begin();
std::advance(it, sparseValue);
_dense.erase(it);
auto revIt = _revSparse.begin();
std::advance(revIt, sparseValue);
_revSparse.erase(revIt);
for (auto revIt2 = _revSparse.begin(); revIt2 != _revSparse.end(); revIt2++) {
if (*revIt2 > id) {
(*revIt2)--;
}
}
for (auto it2 = _sparse.begin(); it2 != _sparse.end(); it2++) {
if (static_cast<int>(*it2) > static_cast<int>(sparseValue)) {
(*it2)--;
Expand Down
16 changes: 10 additions & 6 deletions src/ECS/Systems/Managers/SystemManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "SystemManager.hpp"
#include <algorithm>

namespace Systems {

Expand All @@ -29,32 +30,35 @@ namespace Systems {

void SystemManager::updateSystems()
{
std::size_t i = 0;
std::size_t i = 0;
std::size_t decrease = 0;

_toRemove.clear();
for (auto &system : getSystems()) {
system(_id, i);
i++;
}
std::size_t decrease = 0;
std::sort(_toRemove.begin(), _toRemove.end());
for (auto &id : _toRemove) {
auto it = _modifiedSystems.begin();
std::advance(it, id - decrease);
_modifiedSystems.erase(it);
decrease++;
}
_toRemove.clear();
}

void SystemManager::addSystem(std::function<void(std::size_t, std::size_t)> sys)
{
_modified = true;
if (!_modified) {
_modified = true;
}
_modifiedSystems.push_back(sys);
}

void SystemManager::removeSystem(std::size_t id)
{
_modified = true;
if (!_modified) {
_modified = true;
}
_toRemove.push_back(id);
}

Expand Down
Loading