ELEC2645 (2018/19) / Mbed 2 deprecated el17dg

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

Revision:
21:0eb394495b8a
Child:
27:f05f4e738ba9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/game/geometry.h	Wed Mar 27 00:00:32 2019 +0000
@@ -0,0 +1,43 @@
+#ifndef GEOMETRY_H
+#define GEOMETRY_H
+
+#include <math.h>
+
+struct Point {
+    int x;
+    int y;
+    Point() : x(0), y(0) {}
+    Point(int _x, int _y) : x(_x), y(_y) {}
+    
+    Point operator+ (const Point& rhs) const {
+        Point result(x + rhs.x, y + rhs.y);
+        return result;
+    }
+    Point operator- (const Point& rhs) const {
+        Point result(x - rhs.x, y - rhs.y);
+        return result;
+    }
+    int lengthSquared() {
+        return x * x + y * y;
+    }
+};
+
+class CircleBounds {
+public:
+    Point center;
+    float radius;
+};
+
+inline bool circleCollideTwoObjects(
+    const Point& pos_a, const CircleBounds& bounds_a, 
+    const Point& pos_b, const CircleBounds& bounds_b
+) {
+    Point center_a = pos_a + bounds_a.center;
+    Point center_b = pos_b + bounds_b.center;
+    Point difference = center_a - center_b;
+    return difference.lengthSquared() <= pow(bounds_a.radius + bounds_b.radius, 2);
+}
+
+
+
+#endif
\ No newline at end of file