From 38f14606c78c119d452f302f17329455e29a9a6f Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 10 Mar 2022 19:12:31 +0100 Subject: refactor: rename game initializer & move input config --- src/engine/data/vector2.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/engine/data/vector2.cpp') 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 -- cgit v1.2.3-18-g5258