28 weapon.reload -= delta;
29 const bool fires = pulled && weapon.reload <= 0.0F;
31 weapon.reload += weapon.cooldown;
33 if (weapon.reload < 0.0F) {
49 std::vector<ecs::Entity>& shooters) {
51 const float delta = tick.
delta();
55 shooters.push_back(entity);
73 std::vector<ecs::Entity>& shooters) {
75 const float delta = tick.
delta();
79 shooters.push_back(entity);
106 std::span<const ecs::Entity> shooters) {
110 .position = transform ? transform->get().position :
Vec2{},
Lets systems react to events without knowing who sends them.
Definition event_bus.hpp:31
void publish(const Event &event)
Calls every handler of type Event with event, before returning.
Definition event_bus.hpp:66
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
bool has(Entity entity) const
Tells whether an entity has every listed component.
Definition registry.hpp:114
View< Components... > view()
View on the entities that own all the listed components.
Definition registry.hpp:222
Components shared by the client and the server.
Generational entity handle: an index into the component pools plus a generation.
Typed publish/subscribe event bus with immediate dispatch.
Vector and matrix types of the engine (GLM behind engine names).
Shoot'em up building blocks on top of the ECS: player ships, their controls, weapons and their shots....
Definition components.hpp:5
bool pull_trigger(Weapon &weapon, float delta, bool pulled) noexcept
Counts a weapon's reload down by one tick and fires it if the trigger is pulled.
Definition weapons.hpp:27
void trigger_auto_weapons(ecs::Registry ®istry, const ecs::Tick &tick, std::vector< ecs::Entity > &shooters)
Finds the entities that fire on their own during this tick and reloads them.
Definition weapons.hpp:72
void trigger_weapons(ecs::Registry ®istry, const ecs::Tick &tick, std::vector< ecs::Entity > &shooters)
Finds the ships that fire during this tick and reloads their weapons.
Definition weapons.hpp:48
void publish_shots(core::EventBus &events, const ecs::Registry ®istry, std::span< const ecs::Entity > shooters)
Publishes a ShotFired for each entity that fires during the tick.
Definition weapons.hpp:105
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.
Components of the shoot'em up module: player ships and weapons.
One simulation step, as the systems see it.
Definition system.hpp:23
constexpr float delta() const noexcept
Duration of the step in seconds, to scale values given per second.
Definition system.hpp:32
Weapon that fires on its own, as soon as it is reloaded (enemies).
Definition components.hpp:31
An entity fired: one shot leaves it during the tick.
Definition weapons.hpp:85
bool player
true for a player's ship (it has a PlayerInput), false for an enemy.
Definition weapons.hpp:91
friend bool operator==(const ShotFired &, const ShotFired &)=default
Compares the events.
ecs::Entity shooter
Entity that fired.
Definition weapons.hpp:87
Vec2 position
Where it was (its Transform), the origin if it has none.
Definition weapons.hpp:89
Gun of a ship: how often it can fire.
Definition components.hpp:18
Systems and the scheduler that updates them in order, once per tick.