]> git.localhorst.tv Git - sdl-test8.git/blob - src/game/Entity.h
added collision engine, more or less stole gameplay from sdl-test7
[sdl-test8.git] / src / game / Entity.h
1 /*
2  * Entity.h
3  *
4  *  Created on: Apr 25, 2012
5  *      Author: holy
6  */
7
8 #ifndef GAME_ENTITY_H_
9 #define GAME_ENTITY_H_
10
11 #include "../shape/Shape.h"
12
13 #include <SDL/SDL.h>
14
15 namespace app { class Timer; }
16
17
18 namespace game {
19
20 class Entity {
21
22         friend std::ostream &operator <<(std::ostream &, const Entity &);
23
24         public:
25                 typedef shape::Shape::Scalar Scalar;
26                 typedef shape::Shape::Vector Vector;
27                 typedef shape::Shape::Ray Ray;
28
29         public:
30                 static void CollisionResponse(Entity &a, const Entity::Ray &na, Entity &b);
31
32         public:
33                 explicit Entity(shape::Shape *s, Scalar mass = 1.0) : shape(s), mass(mass) { };
34                 virtual ~Entity(void) { };
35
36         public:
37                 void Update(const app::Timer &);
38                 bool CheckCollision(const Entity &, Ray &);
39
40         public:
41                 virtual void Collide(Entity &other, const Ray &) { };
42                 virtual void Render(SDL_Surface *dest) const { };
43
44         public:
45                 const Vector &Origin(void) const { return translation; };
46                 const Vector &LinearVelocity(void) const { return linearVelocity; };
47                 Scalar Angle(void) const { return rotation; };
48                 Scalar AngularVelocity(void) const { return angularVelocity; };
49                 Vector VelocityAt(const Vector &p) const;
50                 const Scalar Mass(void) const { return mass; };
51
52         public:
53                 void Rotate(Scalar);
54                 void Translate(const Vector &);
55                 void Accelerate(const Vector &linear, Scalar angular = 0);
56
57         private:
58                 static void InfInfCollisionResponse(Entity &a, const Entity::Ray &na, Entity &b);
59
60         private:
61                 shape::Shape *shape;
62                 Vector translation, linearVelocity;
63                 Scalar rotation, angularVelocity, mass;
64
65 };
66
67
68 inline std::ostream &operator <<(std::ostream &out, const Entity &e) {
69         return out << *e.shape;
70 }
71
72 }
73
74 #endif /* GAME_ENTITY_H_ */