R-Type  2
Doom but in better
Loading...
Searching...
No Matches
MovementSystem.cpp
Go to the documentation of this file.
1#include "MovementSystem.hpp"
2#include "IndexedZipper.hpp"
3#include "Time.hpp"
4
5void move_player(Registry &r, std::size_t id, float x, float y)
6{
7 auto &position = r.get_components<Position>();
8 if (position.size() <= id) return;
9
10 position[id]->X = x;
11 position[id]->Y = y;
12
13 r.dispatcher->notify({P_MOVE, id, {0, 0, 0, "", {x, y}}});
14}
15
17{
18 for (auto &&[idx, pos, vel] : IndexedZipper(positions, velocities)) {
19 if (pos && vel) {
20 pos->X += vel->vX * Time::deltaTime;
21 pos->Y += vel->vY * Time::deltaTime;
22 r.dispatcher->notify({P_MOVE, idx, {0, 0, 0, "", {pos->X, pos->Y}}});
23 }
24 }
25}
@ P_MOVE
Represents a movement event.
void move_player(Registry &r, std::size_t id, float x, float y)
Moves a player to a specified position.
void movement_system(Registry &r, ComponentContainer< Position > &positions, ComponentContainer< Velocity > &velocities)
Handles the movement of entities based on their velocity.
Registry * r
Definition Tests.cpp:4
Manages a collection of components associated with entities in an ECS (Entity-Component-System) archi...
void notify(const GameMessage &event)
Notifies the subscribed listener of an event.
Combines multiple containers into a single iterable unit, iterating over corresponding elements from ...
Manages entities and their associated components, enabling the creation, deletion,...
Definition Registry.hpp:23
EventDispatcher * dispatcher
Definition Registry.hpp:191
ComponentContainer< Component > & get_components()
Retrieves the component container for a specific type.
Definition Registry.hpp:121
float deltaTime
The time difference between the current frame and the last frame.
Definition Time.cpp:4
Represents the position of an entity in a 2D space.
Definition Position.hpp:10
float X
Definition Position.hpp:11