diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-10 19:12:31 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:55 +0200 |
commit | 38f14606c78c119d452f302f17329455e29a9a6f (patch) | |
tree | 03f6dfd9d3576e87260f7cb3bc436ad076b629c5 /src/engine/data | |
parent | 09848ad31af6a1c70d64fccee711e231afb5a77f (diff) |
refactor: rename game initializer & move input config
Diffstat (limited to 'src/engine/data')
-rw-r--r-- | src/engine/data/bounds.cpp | 10 | ||||
-rw-r--r-- | src/engine/data/bounds.hpp | 4 | ||||
-rw-r--r-- | src/engine/data/vector2.cpp | 30 | ||||
-rw-r--r-- | src/engine/data/vector2.hpp | 10 |
4 files changed, 49 insertions, 5 deletions
diff --git a/src/engine/data/bounds.cpp b/src/engine/data/bounds.cpp index acd98af..41b6dc0 100644 --- a/src/engine/data/bounds.cpp +++ b/src/engine/data/bounds.cpp @@ -32,11 +32,21 @@ CoordsValidation Bounds::validate_coords(const Vector2 &coords) const noexcept return CoordsValidation::X_HIGH; } + if (static_cast<uint32_t>(coords.get_x()) <= 0) + { + return CoordsValidation::X_LOW; + } + if (static_cast<uint32_t>(coords.get_y()) >= _height) { return CoordsValidation::Y_HIGH; } + if (static_cast<uint32_t>(coords.get_y()) <= 0) + { + return CoordsValidation::Y_LOW; + } + return CoordsValidation::VALID; } diff --git a/src/engine/data/bounds.hpp b/src/engine/data/bounds.hpp index b29005e..9b72f59 100644 --- a/src/engine/data/bounds.hpp +++ b/src/engine/data/bounds.hpp @@ -8,7 +8,9 @@ enum CoordsValidation { VALID, X_HIGH, - Y_HIGH + X_LOW, + Y_HIGH, + Y_LOW }; struct BoundsOptions diff --git a/src/engine/data/vector2.cpp b/src/engine/data/vector2.cpp index f91afa8..04cc42e 100644 --- a/src/engine/data/vector2.cpp +++ b/src/engine/data/vector2.cpp @@ -24,6 +24,12 @@ void Vector2::set_y(Vector2::Value y) noexcept _y = y; } +Vector2 Vector2::to_direction(const Vector2 &direction, + Vector2::Value amount) const noexcept +{ + return *this + (direction * Vector2({.x = amount, .y = amount})); +} + const Vector2 &Vector2::operator+=(const Vector2 &vector2) noexcept { _x += vector2._x; @@ -40,6 +46,26 @@ const Vector2 &Vector2::operator-=(const Vector2 &vector2) noexcept return *this; } +Vector2 Vector2::operator+(const Vector2 &vector2) const noexcept +{ + auto new_vector2 = Vector2(*this); + + new_vector2._x += vector2._x; + new_vector2._y += vector2._y; + + return new_vector2; +} + +Vector2 Vector2::operator*(const Vector2 &vector2) const noexcept +{ + auto new_vector2 = Vector2(*this); + + new_vector2._x *= vector2._x; + new_vector2._y *= vector2._y; + + return new_vector2; +} + bool Vector2::operator==(const Vector2 &vector2) const noexcept { return _x == vector2._x && _y == vector2._y; @@ -47,12 +73,12 @@ bool Vector2::operator==(const Vector2 &vector2) const noexcept Vector2 Vector2::up() noexcept { - return Vector2({.x = 0, .y = 1}); + return Vector2({.x = 0, .y = -1}); } Vector2 Vector2::down() noexcept { - return Vector2({.x = 0, .y = -1}); + return Vector2({.x = 0, .y = 1}); } Vector2 Vector2::left() noexcept diff --git a/src/engine/data/vector2.hpp b/src/engine/data/vector2.hpp index 49e5d85..e835e65 100644 --- a/src/engine/data/vector2.hpp +++ b/src/engine/data/vector2.hpp @@ -27,18 +27,24 @@ public: void set_y(Value y) noexcept; + [[nodiscard]] Vector2 to_direction(const Vector2 &direction, + Vector2::Value amount) const noexcept; + const Vector2 &operator+=(const Vector2 &vector2) noexcept; const Vector2 &operator-=(const Vector2 &vector2) noexcept; + Vector2 operator+(const Vector2 &vector2) const noexcept; + Vector2 operator*(const Vector2 &vector2) const noexcept; + bool operator==(const Vector2 &vector2) const noexcept; /** - * Returns Vector2({.x = 0, .y = 1}) + * Returns Vector2({.x = 0, .y = -1}) */ static Vector2 up() noexcept; /** - * Returns Vector2({.x = 0, .y = -1}) + * Returns Vector2({.x = 0, .y = 1}) */ static Vector2 down() noexcept; |