aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Velocity.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/Velocity.hpp')
-rw-r--r--src/components/Velocity.hpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/components/Velocity.hpp b/src/components/Velocity.hpp
index 776c1dd..888cbb5 100644
--- a/src/components/Velocity.hpp
+++ b/src/components/Velocity.hpp
@@ -25,25 +25,24 @@
struct Velocity : Component<Velocity>
{
public:
- double x, y;
+ float x, y;
- Velocity(double _x = 0, double _y = 0) :
+ Velocity(float _x = 0, float _y = 0) :
x(_x), y(_y) {}
Velocity FromLua(sol::object ref)
{
- if (ref.get_type() == sol::type::table) {
- sol::table tab = ref;
- if (tab["x"] != nullptr)
- this->x = tab["x"];
- if (tab["y"] != nullptr)
- this->y = tab["y"];
- } else {
- throw std::string("Velocity table not formatted properly");
- }
+ glm::vec2 vel = Script::to<glm::vec2>(ref);
+ this->x = vel.x;
+ this->y = vel.y;
return *this;
}
+ glm::vec2 vec()
+ {
+ return glm::vec2(x, y);
+ }
+
void serialize(cereal::JSONOutputArchive& ar) final {
ar(CEREAL_NVP(x), CEREAL_NVP(y));
}