ELEC2645 (2018/19) / Mbed 2 deprecated el17dg

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

game/geometry.h

Committer:
Noximilien
Date:
2019-04-10
Revision:
28:35af3843de8f
Parent:
27:f05f4e738ba9
Child:
29:579e00b7f118

File content as of revision 28:35af3843de8f:

#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:
    CircleBounds() {};
    CircleBounds(Point _center, float _radius): center(_center), radius(_radius) {};
    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