static void movePacketHandle(
World & world,
network::Message & msg
)
function firstMessageHandle
static void firstMessageHandle(
World & world,
network::Message & msg
)
function deathMessageHandle
static void deathMessageHandle(
World & world,
network::Message & msg
)
function playerHealthHandle
static void playerHealthHandle(
World & world,
network::Message & msg
)
function createPlayer
static void createPlayer(
World & world,
network::ClientMessage & msg
)
Parameters:
world The world in which we want to operate
msg The message of a new player coming on the server
In goal of create a player, first, we need to add every components of the player. Specify to the server that there is a new connection and check if the request has been accepted
function movePlayer
static void movePlayer(
World & world,
network::ClientMessage & msg
)
Parameters:
world The world we want to operate
msg The message containing the new position of the player
Updating the player position according to the given msg
function playerShoot
static void playerShoot(
World & world,
network::ClientMessage & msg
)
Parameters:
world The world we want to operate
msg Only used to compare ID and select the correct player
Used to make the player shoot from the given message
Attributes Documentation
variable animate
std::function< void(World &)> animate = [](World &world) {
auto &animateds = world.registry.getComponents<component::Animated>();
using chrono = std::chrono::high_resolution_clock;
using chronoDuration = std::chrono::duration<double, std::milli>;
for (size_t i = 0; i < animateds.size(); ++i) {
auto &anim = animateds[i];
if (anim) {
if (chrono::now().time_since_epoch().count() - anim.value().lastSwitch
> static_cast<size_t>(anim.value().getFrame().delay) * 1000000) {
anim.value().nextFrame();
anim.value().lastSwitch = chrono::now().time_since_epoch().count();
}
}
}
};
variable draw
std::function< void(World &)> draw;
Used to set the scale, the position and the texture of the entity before display it
std::function< void(World &)> HandleParallaxBounds = [](World &world) {
auto ¶llaxes = world.registry.getComponents<component::Parallax>();
auto &positions = world.registry.getComponents<component::Position>();
for (size_t i = 0; i < parallaxes.size() && i < positions.size(); i++) {
if (!parallaxes[i] || !positions[i])
continue;
if (positions[i].value().x < parallaxes[i].value().threshold) {
positions[i].value().x += parallaxes[i].value().position;
}
}
};
variable handleSFMLEvents
std::function< void(World &)> handleSFMLEvents;
Used to manage Sfml events Currently able to manage the following actions: Close the window KeyPressed, in this case, we check if the bind is known from sfml: if yes, we had it on world's events' stack, nothing otherwise
variable handleSFMLKeys
std::function< void(World &)> handleSFMLKeys;
variable healthBar
std::function< void(World &)> healthBar = [](World &world) {
auto const &positions = world.registry.getComponents<component::Position>();
auto &sizes = world.registry.getComponents<component::Size>();
auto const &healths = world.registry.getComponents<component::Health>();
for (size_t i = 0; i < positions.size() && i < sizes.size() && i < healths.size(); i++) {
auto const &pos = positions[i];
auto &size = sizes[i];
auto const &health = healths[i];
if (pos && size && health) {
if (health->health >= 0 && health->health < utils::constant::maxPlayerHealth) {
size.value().width = utils::constant::sizeHealthBar * health->health / 100;
} else if (health->health < 0)
size.value().width = 0;
else
size.value().width = utils::constant::sizeHealthBar;
}
}
};
variable menuSelect
std::function< void(World &)> menuSelect;
variable scoreUpdate
std::function< void(World &)> scoreUpdate = [](World &world) {
auto &texts = world.registry.getComponents<component::Text>();
auto &scores = world.registry.getComponents<component::Score>();
for (size_t i = 0; i < texts.size() || i < scores.size(); i++) {
auto &text = texts[i];
auto &score = scores[i];
if (text && score) {
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
auto time = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() / 10;
auto elapsed = std::to_string(time);
const std::string string = "Score: ";
text->setContent(0, string);
text->setContent(1, elapsed);
score->setScore(time);
}
}
};
Used to set the score of the player
variable SendDirection
std::function< void(World &)> SendDirection = [](World &world) {
auto const &controllables = world.registry.getComponents<component::Controllable>();
auto &directions = world.registry.getComponents<component::Direction>();
static auto clock = utils::constant::chrono::now();
if (utils::constant::chronoDuration(utils::constant::chrono::now() - clock).count() > 10) {
clock = utils::constant::chrono::now();
for (size_t i = 0; i < controllables.size() && i < directions.size(); i++) {
if (!controllables[i] || !directions[i])
continue;
if (directions[i].value().hasMoved) {
network::Message msg;
msg.fill(0);
msg[0] = utils::constant::PLAYER_MOVE;
msg[1] = directions[i].value().x;
msg[2] = directions[i].value().y;
network::Client::getOutgoingMessages().push(msg);
directions[i].value().hasMoved = false;
}
}
}
};
Send direction system used to fill the array of messages to the server regarding the direction of the player
variable manageClientEvents
std::function< void(World &)> manageClientEvents;
Used to manage every client' events Refer to SFMLEvents.hpp documentation to learn more about managed events
variable movement
std::function< void(World &)> movement;
Used to apply the values of the velocity component to the position component according to the internal clock of the system
variable positionLogger
std::function< void(World &)> positionLogger = [](World &world) {
auto const &positions = world.registry.getComponents<component::Position>();
auto const &velocities = world.registry.getComponents<component::Velocity>();
for (size_t i = 0; i < positions.size() && i < velocities.size(); ++i) {
auto const &pos = positions[i];
auto const &vel = velocities[i];
if (pos && vel) {
std ::cerr << i << ": Position = { " << pos.value().x << ", " << pos.value().y << " }, Velocity = { "
<< vel.value().x << ", " << vel.value().y << " } " << std ::endl;
}
};
};
Used to display, as a logger, all the value of the Position & Velocity component
variable runMovementAI
std::function< void(World &)> runMovementAI = [](World &world) {
auto &directions = world.registry.getComponents<component::Direction>();
auto &movementAIs = world.registry.getComponents<component::MovementAI>();
using chrono = std::chrono::high_resolution_clock;
using chronoDuration = std::chrono::duration<double, std::milli>;
for (size_t i = 0; i < directions.size() && i < movementAIs.size(); ++i) {
auto &dir = directions[i];
auto &movAI = movementAIs[i];
if (dir && movAI) {
if ((chrono::now().time_since_epoch().count() - movAI.value().getLastMovement()) / 10000000
> static_cast<size_t>(movAI.value().getDelay())) {
auto &tmpDir = movAI.value().getNextDirection();
dir.value().x = tmpDir.first;
dir.value().y = tmpDir.second;
dir.value().hasMoved = true;
movAI.value().setLastMovement(chrono::now().time_since_epoch().count());
}
}
};
};
Runs the AIs stored in the enities
variable deathUpdate
std::function< void(World &)> deathUpdate;
System used to push death of entity message to the server outgoing queue when is life as gone under 0.
variable followEntitySystem
std::function< void(World &)> followEntitySystem = [](World &world) {
auto &positions = world.registry.getComponents<component::Position>();
auto const &follows = world.registry.getComponents<component::FollowEntity>();
for (std::size_t i = 0; i < positions.size() && i < follows.size(); i++) {
auto &pos = positions[i];
auto const &fol = follows[i];
if (pos && fol) {
if (fol.value().entityId < positions.size()) {
if (positions[fol.value().entityId]) {
pos.value().x = positions[fol.value().entityId].value().x - 50;
pos.value().y = positions[fol.value().entityId].value().y + 50;
}
}
}
}
};