aboutsummaryrefslogtreecommitdiff
path: root/src/engine/graphics
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-02-27 15:24:07 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:53 +0200
commit2bcf699b9e11ccf848393882257fc3986bd28e45 (patch)
treea7ea1033984a857812297b0b41bd322c57a3b23f /src/engine/graphics
parent5864e5abc43b201c3801fa39a2fcaf9e3a9e8914 (diff)
add game & vector2
Diffstat (limited to 'src/engine/graphics')
-rw-r--r--src/engine/graphics/vector2.cpp39
-rw-r--r--src/engine/graphics/vector2.hpp48
2 files changed, 87 insertions, 0 deletions
diff --git a/src/engine/graphics/vector2.cpp b/src/engine/graphics/vector2.cpp
new file mode 100644
index 0000000..dfdf4bd
--- /dev/null
+++ b/src/engine/graphics/vector2.cpp
@@ -0,0 +1,39 @@
+#include "vector2.hpp"
+
+Vector2::Vector2(const IVector2Options &options) : _x(options.x), _y(options.y) {}
+
+unsigned int Vector2::x() const
+{
+ return _x;
+}
+
+void Vector2::x(unsigned int x)
+{
+ _x = x;
+}
+
+unsigned int Vector2::y() const
+{
+ return _y;
+}
+
+void Vector2::y(unsigned int y)
+{
+ _y = y;
+}
+
+const IVector2 &Vector2::operator+=(const IVector2 &vector2)
+{
+ _x += vector2.x();
+ _y += vector2.y();
+
+ return *this;
+}
+
+const IVector2 &Vector2::operator-=(const IVector2 &vector2)
+{
+ _x -= vector2.x();
+ _y -= vector2.y();
+
+ return *this;
+}
diff --git a/src/engine/graphics/vector2.hpp b/src/engine/graphics/vector2.hpp
new file mode 100644
index 0000000..c8c6349
--- /dev/null
+++ b/src/engine/graphics/vector2.hpp
@@ -0,0 +1,48 @@
+#pragma once
+
+#include "interfaces/vector2.hpp"
+
+#include <memory>
+
+/**
+ * A 2D Vector.
+ */
+class Vector2 : public IVector2
+{
+public:
+ /**
+ * Creates a 2D vector.
+ */
+ explicit Vector2(const IVector2Options &options);
+
+ /**
+ * Returns the X coordinate.
+ */
+ [[nodiscard]] unsigned int x() const override;
+
+ /**
+ * Sets the X coordinate.
+ *
+ * @param x A new X coordinate
+ */
+ void x(unsigned int x) override;
+
+ /**
+ * Returns the Y coordinate.
+ */
+ [[nodiscard]] unsigned int y() const override;
+
+ /**
+ * Sets the Y coordinate.
+ *
+ * @param Y A new Y coordinate
+ */
+ void y(unsigned int y) override;
+
+ const IVector2 &operator+=(const IVector2 &vector2) override;
+ const IVector2 &operator-=(const IVector2 &vector2) override;
+
+private:
+ unsigned int _x;
+ unsigned int _y;
+};