28 [[nodiscard]]
constexpr bool out() const noexcept {
return lives_left == 0; }
49 std::vector<LifeLost>& lost) {
56 Lives& player = *lives;
57 if (player.
count > 0) {
60 if (player.
count > 0) {
62 health->get().points = player.
health;
65 transform->get().position = player.
spawn;
68 velocity->get().value =
Vec2{};
73 .lives_left = player.
count,
74 .score = score ? score->get().points : 0U});
Handle to an entity: 32 bits made of a 24-bit index and an 8-bit generation.
Definition entity.hpp:23
Entry point of the ECS: creates entities and stores their components.
Definition registry.hpp:34
std::optional< std::reference_wrapper< Component > > try_get(Entity entity)
Component of an entity, if it has one.
Definition registry.hpp:147
std::size_t count() const
Number of entities that have a component.
Definition registry.hpp:170
Damage on hit: turns collision contacts into lost health, kills and spent missiles.
Components shared by the client and the server.
Generational entity handle: an index into the component pools plus a generation.
Vector and matrix types of the engine (GLM behind engine names).
Entity-Component-System used by client and server.
Definition animation.hpp:13
std::size_t players_left(const Registry ®istry)
Number of players still in the game.
Definition lives.hpp:83
bool game_over(const Registry ®istry)
Tells whether every player is out.
Definition lives.hpp:93
void handle_player_deaths(Registry ®istry, const DamageReport &report, std::vector< LifeLost > &lost)
Takes a life from each killed player and respawns those who have some left.
Definition lives.hpp:48
glm::vec2 Vec2
2D vector of floats: positions, velocities, sizes (glm::vec2).
Definition math.hpp:19
Registry: owns the entities and one component pool per component type.
What apply_damage() did during one tick, in the order of the contacts.
Definition damage.hpp:45
std::vector< Kill > kills
Entities whose health reached zero or less during the tick, once each.
Definition damage.hpp:49
How much damage an entity can still take.
Definition components.hpp:115
An entity whose health reached zero, and the hit that did it.
Definition damage.hpp:32
A player who lost a life during the tick.
Definition lives.hpp:17
std::uint32_t score
The player's Score at that moment (0 without a Score), kept for the end screen since an out player is...
Definition lives.hpp:24
friend constexpr bool operator==(const LifeLost &, const LifeLost &) noexcept=default
Compares the events.
std::uint32_t lives_left
Lives left after this death; 0 means the player is out.
Definition lives.hpp:21
Entity player
The player.
Definition lives.hpp:19
constexpr bool out() const noexcept
Tells whether the player has no life left.
Definition lives.hpp:28
Lives of a player, and how it comes back after losing one.
Definition components.hpp:158
Vec2 spawn
Where the player respawns (Transform::position).
Definition components.hpp:162
std::uint32_t count
Lives left, the current one included; 0 once the player is out.
Definition components.hpp:160
std::int32_t health
Health points given back on respawn.
Definition components.hpp:164
Points a player has earned.
Definition components.hpp:143
How fast an entity moves.
Definition components.hpp:25