Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
MovementSystem.cpp
Go to the documentation of this file.
1
9
10namespace rtp::server
11{
13 // Public API
15
17 : _registry(registry) {}
18
20 {
21 auto view = _registry.zipView<
24 >();
25
26 for (auto&& [tf, vel] : view) {
27 // Handle both conventions:
28 // 1. Old: direction contains velocity (pixels/sec), speed=0
29 // 2. New: direction is normalized, speed is separate
30 if (vel.speed > 0.0f) {
31 tf.position.x += vel.direction.x * vel.speed * dt;
32 tf.position.y += vel.direction.y * vel.speed * dt;
33 } else {
34 tf.position.x += vel.direction.x * dt;
35 tf.position.y += vel.direction.y * dt;
36 }
37 }
38
39 auto playerView = _registry.zipView<
43 >();
44
45 constexpr float kWindowWidth = 1280.0f;
46 constexpr float kWindowHeight = 720.0f;
47
48 for (auto&& [tf, box, type] : playerView) {
49 if (type.type != net::EntityType::Player) {
50 continue;
51 }
52
53 if (tf.position.x < 0.0f) tf.position.x = 0.0f;
54 if (tf.position.y < 0.0f) tf.position.y = 0.0f;
55
56 const float maxX = kWindowWidth - box.width;
57 const float maxY = kWindowHeight - box.height;
58
59 if (tf.position.x > maxX) tf.position.x = maxX;
60 if (tf.position.y > maxY) tf.position.y = maxY;
61 }
62 }
63} // namespace rtp::server
auto zipView(this Self &self)
MovementSystem(ecs::Registry &registry)
Constructor for MovementSystem.
ecs::Registry & _registry
Reference to the entity registry.
void update(float dt) override
Update movement system logic for one frame.
File : GameManager.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue....
Component representing position, rotation, and scale of an entity.
Definition Transform.hpp:23
Component representing a 2D velocity.
Definition Velocity.hpp:17
Vec2f direction
Velocity in X and Y directions.
Definition Velocity.hpp:18