]> git.localhorst.tv Git - sdl-test8.git/blobdiff - src/game/Entity.h
added collision engine, more or less stole gameplay from sdl-test7
[sdl-test8.git] / src / game / Entity.h
diff --git a/src/game/Entity.h b/src/game/Entity.h
new file mode 100644 (file)
index 0000000..22d46bd
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Entity.h
+ *
+ *  Created on: Apr 25, 2012
+ *      Author: holy
+ */
+
+#ifndef GAME_ENTITY_H_
+#define GAME_ENTITY_H_
+
+#include "../shape/Shape.h"
+
+#include <SDL/SDL.h>
+
+namespace app { class Timer; }
+
+
+namespace game {
+
+class Entity {
+
+       friend std::ostream &operator <<(std::ostream &, const Entity &);
+
+       public:
+               typedef shape::Shape::Scalar Scalar;
+               typedef shape::Shape::Vector Vector;
+               typedef shape::Shape::Ray Ray;
+
+       public:
+               static void CollisionResponse(Entity &a, const Entity::Ray &na, Entity &b);
+
+       public:
+               explicit Entity(shape::Shape *s, Scalar mass = 1.0) : shape(s), mass(mass) { };
+               virtual ~Entity(void) { };
+
+       public:
+               void Update(const app::Timer &);
+               bool CheckCollision(const Entity &, Ray &);
+
+       public:
+               virtual void Collide(Entity &other, const Ray &) { };
+               virtual void Render(SDL_Surface *dest) const { };
+
+       public:
+               const Vector &Origin(void) const { return translation; };
+               const Vector &LinearVelocity(void) const { return linearVelocity; };
+               Scalar Angle(void) const { return rotation; };
+               Scalar AngularVelocity(void) const { return angularVelocity; };
+               Vector VelocityAt(const Vector &p) const;
+               const Scalar Mass(void) const { return mass; };
+
+       public:
+               void Rotate(Scalar);
+               void Translate(const Vector &);
+               void Accelerate(const Vector &linear, Scalar angular = 0);
+
+       private:
+               static void InfInfCollisionResponse(Entity &a, const Entity::Ray &na, Entity &b);
+
+       private:
+               shape::Shape *shape;
+               Vector translation, linearVelocity;
+               Scalar rotation, angularVelocity, mass;
+
+};
+
+
+inline std::ostream &operator <<(std::ostream &out, const Entity &e) {
+       return out << *e.shape;
+}
+
+}
+
+#endif /* GAME_ENTITY_H_ */