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/vector2.cpp | |
parent | 09848ad31af6a1c70d64fccee711e231afb5a77f (diff) |
refactor: rename game initializer & move input config
Diffstat (limited to 'src/engine/data/vector2.cpp')
-rw-r--r-- | src/engine/data/vector2.cpp | 30 |
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 |