|
Aegis2D
Modular C++26 2D game engine for networked games
|
Shoot'em up building blocks on top of the ECS: player ships, their controls, weapons and their shots. A game of another genre leaves the module out. More...
Classes | |
| struct | AutoTrigger |
| Weapon that fires on its own, as soon as it is reloaded (enemies). More... | |
| struct | PlayerShip |
Ship steered by a player's input (ecs::PlayerInput). More... | |
| class | ShipControls |
| The controls of a player ship: arrows move it and Space fires, or a gamepad's D-pad or left stick and its South button (A, Cross) or right trigger. More... | |
| struct | ShotFired |
| An entity fired: one shot leaves it during the tick. More... | |
| struct | Weapon |
| Gun of a ship: how often it can fire. More... | |
Functions | |
| AEGIS2D_SHMUP_EXPORT std::string_view | name () noexcept |
| Name of the module, used to check that it is linked. | |
| void | steer_player_ships (ecs::Registry ®istry, const ecs::Tick &tick) |
| Sets the velocity of every player ship from its input. | |
| void | clamp_player_ships (ecs::Registry ®istry, const ecs::Aabb &area) |
| Keeps every player ship inside the play area. | |
| ecs::Entity | spawn_player_ship (ecs::Registry ®istry, Vec2 position, float speed=PlayerShip{}.speed) |
| Creates a player ship ready to be steered. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
Shoot'em up building blocks on top of the ECS: player ships, their controls, weapons and their shots. A game of another genre leaves the module out.
|
inline |
Keeps every player ship inside the play area.
Each entity with PlayerShip and ecs::Transform is moved back so that its box (see ecs::half_extent_of()) fits in area: holding a direction against an edge stops the ship there, and it can leave the edge at once in the other direction. Run it after ecs::apply_velocity() and before the collisions, e.g. systems.add("clamp", [area](ecs::Registry& r, const ecs::Tick&) { shmup::clamp_player_ships(r, area); });. Defined in the header because it reads components.
| registry | World holding the ships. |
| area | Play area, usually {0, 0} to the logical resolution (#85). |
|
noexcept |
Name of the module, used to check that it is linked.
"shmup", a view of a static string.
|
inline |
Publishes a ShotFired for each entity that fires during the tick.
Call it after trigger_weapons() or trigger_auto_weapons(), with their shooters, in their order. Defined in the header, like the systems, because it reads components (see ecs::CollisionGrid::build()) and publishes in the caller's code (the bus finds its handlers by typeid).
| events | Bus to publish on. |
| registry | World holding the shooters. |
| shooters | Entities that fire this tick. |
|
inlinenoexcept |
Counts a weapon's reload down by one tick and fires it if the trigger is pulled.
The reload goes down by delta. If pulled and the weapon is ready, it fires and the cooldown is added to the reload; the time left over is kept, so the rate is exact over many ticks even when the cooldown is not a whole number of ticks. A weapon that stays idle does not store shots: its reload stops at zero.
| weapon | Weapon to update. |
| delta | Duration of the tick, in seconds. |
| pulled | true if the weapon should fire when ready. |
true if it fires during this tick.
|
inline |
Creates a player ship ready to be steered.
The ship gets an ecs::Transform at position, a zero ecs::Velocity, an empty ecs::PlayerInput and a PlayerShip with speed. The game adds what depends on it: Collider layers, Health, Lives, Score, Sprite.
| registry | World to create it in. |
| position | Center of the ship, in logical pixels. |
| speed | Speed in logical pixels per second. |
|
inline |
Sets the velocity of every player ship from its input.
For each entity with PlayerShip, ecs::PlayerInput and ecs::Velocity, the velocity becomes ecs::direction_of(input) * speed: the ship moves while a direction is held and stops as soon as it is released. Runs on the server, which owns the simulation; the signature lets it be added to a Scheduler as is. Defined in the header because it reads components (see ecs::CollisionGrid::build()).
| registry | World holding the ships. |
| tick | Unused: the speed is per second, applied by ecs::apply_velocity(). |
|
inline |
Finds the entities that fire on their own during this tick and reloads them.
For each entity with Weapon and AutoTrigger but no PlayerInput, pull_trigger() counts the reload down and fires as soon as the weapon is ready: the entity shoots every cooldown seconds, the first time when its first reload runs out. The game then creates one missile per shooter, e.g. in front of an enemy. Run it next to trigger_weapons(), e.g. systems.add("enemy_fire", [&shooters](ecs::Registry& r, const ecs::Tick& t) { shmup::trigger_auto_weapons(r, t, shooters); });. Defined in the header because it reads components.
| registry | World holding the weapons. |
| tick | Step of the simulation. |
| shooters | Cleared, then filled with the entities that fire this tick. |
|
inline |
Finds the ships that fire during this tick and reloads their weapons.
For each entity with Weapon and PlayerInput, pull_trigger() counts the reload down and fires when Action::Fire is held and the weapon is ready; the entity is then added to shooters. The game then creates one missile per shooter (its spawn rules are its own). Defined in the header because it reads components (see ecs::CollisionGrid::build()).
| registry | World holding the weapons. |
| tick | Step of the simulation. |
| shooters | Cleared, then filled with the entities that fire this tick. |