]> git.localhorst.tv Git - sdl-test7.git/blob - src/game/Entity.h
imported current version
[sdl-test7.git] / src / game / Entity.h
1 /*
2  * Entity.h
3  *
4  *  Created on: Apr 9, 2012
5  *      Author: holy
6  */
7
8 #ifndef GAME_ENTITY_H_
9 #define GAME_ENTITY_H_
10
11 #include "../geometry/Shape.h"
12 #include "../geometry/Vector2D.h"
13
14 #include <cmath>
15 #include <ostream>
16 #include <SDL/SDL.h>
17
18
19 namespace game {
20
21 class Entity {
22
23         public:
24                 typedef geometry::Shape::Scalar Scalar;
25                 typedef geometry::Shape::Vector Vector;
26                 typedef geometry::Shape::Limits Limits;
27
28         public:
29                 explicit Entity(geometry::Shape *);
30                 Entity(const Vector &position, geometry::Shape *);
31                 virtual ~Entity(void);
32
33         public:
34                 void Move(const Vector &d);
35
36                 void SetPosition(const Vector &);
37
38         public:
39                 const Vector &Position(void) const { return position; };
40                 Vector Center(void) const;
41                 const Vector &Velocity() const { return velocity; };
42                 void SetVelocity(const Vector &);
43
44         public:
45                 const geometry::Shape &Bounds(void) const { return *bounds; };
46                 bool Overlaps(const Entity &other, Vector &normal) {
47                         return bounds->Overlaps(*other.bounds, normal);
48                 };
49
50         public:
51                 void Update(float deltaT);
52                 void Revert(float deltaT);
53                 virtual void Collide(Entity &, const Vector &normal);
54                 virtual void PostCollide(void);
55                 virtual void Render(SDL_Surface *dest) { };
56
57         public:
58                 bool IsDynamic(void) const { return dynamic; };
59                 bool IsStatic(void) const { return !dynamic; };
60                 void SetDynamic(void) { dynamic = true; };
61                 void SetStatic(void) { dynamic = false; };
62
63         public:
64                 void Accelerate(float factor);
65                 void SetMaxVelocity(float);
66
67         private:
68                 geometry::Shape *bounds;
69                 Vector position, velocity, nextVelocity;
70                 Scalar maxVelocitySquared;
71                 bool dynamic, updateVelocity;
72 };
73
74 }
75
76 #endif /* GAME_ENTITY_H_ */