R-Type 0.1
Loading...
Searching...
No Matches
Velocity.hpp
1#pragma once
2
3#include <cstdint>
4#include <nlohmann/json.hpp>
5
6#include <Registry.hpp>
7
8namespace component {
17struct Velocity {
18 float x{0.0f};
19 float y{0.0f};
20};
21
28inline void velocityFromJson(rtk::ecs::Registry &reg, std::size_t entity,
29 const nlohmann::json &data) {
30 component::Velocity velocity{};
31 velocity.x = data.value("x", 0.0f);
32 velocity.y = data.value("y", 0.0f);
33
34 reg.get_components<component::Velocity>().insert_at(entity, velocity);
35}
36
38} // namespace component
void velocityFromJson(rtk::ecs::Registry &reg, std::size_t entity, const nlohmann::json &data)
Adds a Velocity to an entity from its blueprint data.
Definition Velocity.hpp:28
Linear speed of an entity.
Definition Velocity.hpp:17
float y
Vertical speed in pixels per second.
Definition Velocity.hpp:19
float x
Horizontal speed in pixels per second.
Definition Velocity.hpp:18