Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions assets/Json/parallaxData.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"y": 0.0
},
"velocity" : {
"speedX" : -0.5,
"speedX" : -0.15,
"speedY" :0.0
},
"copy": true
Expand All @@ -23,7 +23,7 @@
"y": 20.0
},
"velocity" : {
"speedX" : -0.8,
"speedX" : -0.1,
"speedY" :0.0
},
"rect" : {
Expand Down
2 changes: 1 addition & 1 deletion 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 Down
14 changes: 14 additions & 0 deletions src/Client/Systems/Network/ClientNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,18 @@ namespace Systems {
}
}
}

void receiveEnemyDeath(std::any &any, boost::asio::ip::udp::endpoint &)
{
struct msgEnemyDeath_s enemyDeath = std::any_cast<struct msgEnemyDeath_s>(any);
Registry::components<Types::Enemy> enemies = Registry::getInstance().getComponents<Types::Enemy>();
std::vector<std::size_t> ids = enemies.getExistingsId();

for (auto id : ids) {
if (enemies[id].constId.value == enemyDeath.enemyId.value) {
Registry::getInstance().removeEntity(id);
return;
}
}
}
} // namespace Systems
3 changes: 2 additions & 1 deletion src/Client/Systems/Network/ClientNetwork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

namespace Systems {
void receiveLifeUpdate(std::any &any, boost::asio::ip::udp::endpoint &endpoint);
}
void receiveEnemyDeath(std::any &any, boost::asio::ip::udp::endpoint &endpoint);
} // namespace Systems
14 changes: 11 additions & 3 deletions src/ECS/ECSCustomTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
#include <cstddef>
#include <functional>
#include <optional>
#include "MessageTypes.h"
#include "nlohmann/json.hpp"

// all values are in percentage of the screen

#include "MessageTypes.h"

namespace Types {

enum MissileTypes { CLASSIC };
Expand Down Expand Up @@ -65,7 +64,16 @@ namespace Types {

struct EnemyAllies { };

struct Enemy { };
static long int enemyNb = 0;

struct Enemy {
Enemy()
{
constId.value = enemyNb;
enemyNb++;
}
struct enemy_id_s constId;
};

struct Parallax { };

Expand Down
4 changes: 4 additions & 0 deletions src/ECS/MessageTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ PACK(struct health_s {
int hp;
});

PACK(struct enemy_id_s {
long int value;
});

#endif
6 changes: 4 additions & 2 deletions src/ECS/Systems/Systems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ namespace Systems {
{
Registry::components<Types::Damage> arrDamage =
Registry::getInstance().getComponents<Types::Damage>();
Registry::components<health_s> arrHealth = Registry::getInstance().getComponents<health_s>();
Registry::components<struct health_s> arrHealth =
Registry::getInstance().getComponents<struct health_s>();

if (checkAllies(firstEntity, secondEntity)) {
return;
Expand Down Expand Up @@ -322,7 +323,8 @@ namespace Systems {

void deathChecker(std::size_t /*unused*/, std::size_t /*unused*/)
{
Registry::components<health_s> arrHealth = Registry::getInstance().getComponents<health_s>();
Registry::components<struct health_s> arrHealth =
Registry::getInstance().getComponents<struct health_s>();
Registry::components<Types::Dead> arrDead = Registry::getInstance().getComponents<Types::Dead>();

std::vector<std::size_t> ids = arrHealth.getExistingsId();
Expand Down
16 changes: 14 additions & 2 deletions src/Nitwork/Nitwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum n_actionType_t {
READY = 2,
START_GAME = 3,
LIFE_UPDATE = 4,
ENEMY_DEATH = 5,
N_ACTION_TYPE_MAX,
};

Expand Down Expand Up @@ -91,14 +92,25 @@ PACK(struct packetMsgStartGame_s {
/* Message Life Update */
PACK(struct msgLifeUpdate_s {
n_magick_t magick;
n_id_t playerId;
struct health_s life;
});

PACK(struct packetLifeUpdate_s {
struct header_s header;
struct action_s action;
struct msgLifeUpdate_s msg;
struct msgLifeUpdate_s msgLifeUpdate;
});

/* Message Enemy Death */
PACK(struct msgEnemyDeath_s {
n_magick_t magick;
struct enemy_id_s enemyId;
});

PACK(struct packetEnemyDeath_s {
struct header_s header;
struct action_s action;
struct msgEnemyDeath_s msgEnemyDeath;
});

#endif
13 changes: 12 additions & 1 deletion src/Nitwork/NitworkClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,23 @@ namespace Nitwork {
LIFE_UPDATE,
{
[this](actionHandler &handler, const struct header_s &header) {
handleBody<struct msgStartGame_s>(handler, header);
handleBody<struct msgLifeUpdate_s>(handler, header);
},
[](std::any &any, boost::asio::ip::udp::endpoint &endpoint) {
Systems::receiveLifeUpdate(any, endpoint);
}
}
},
{
ENEMY_DEATH,
{
[this](actionHandler &handler, const struct header_s &header) {
handleBody<struct msgEnemyDeath_s>(handler, header);
},
[](std::any &any, boost::asio::ip::udp::endpoint &endpoint) {
Systems::receiveEnemyDeath(any, endpoint);
}
}
}
};
std::map<
Expand Down