aboutsummaryrefslogtreecommitdiff
path: root/src/engine/data/vector2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/data/vector2.cpp')
-rw-r--r--src/engine/data/vector2.cpp30
1 files changed, 28 insertions, 2 deletions
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