]> git.localhorst.tv Git - l2e.git/blob - src/map/Entity.h
store complete entity in hero
[l2e.git] / src / map / Entity.h
1 /*
2  * Entity.h
3  *
4  *  Created on: Sep 29, 2012
5  *      Author: holy
6  */
7
8 #ifndef MAP_ENTITY_H_
9 #define MAP_ENTITY_H_
10
11 #include "../geometry/Vector.h"
12 #include "../graphics/fwd.h"
13 #include "../graphics/Animation.h"
14
15 #include <functional>
16 #include <SDL.h>
17
18 namespace map {
19
20 class Entity {
21
22 public:
23         Entity();
24         ~Entity() { }
25
26 public:
27         enum Orientation {
28                 ORIENTATION_NORTH = 0,
29                 ORIENTATION_EAST = 1,
30                 ORIENTATION_SOUTH = 2,
31                 ORIENTATION_WEST = 3,
32         };
33         enum Flags {
34                 FLAG_NONBLOCKING = 0x01,
35         };
36
37 public:
38         geometry::Vector<float> &Position() { return position; }
39         const geometry::Vector<float> &Position() const { return position; }
40
41         geometry::Vector<float> &Velocity() { return velocity; }
42         const geometry::Vector<float> &Velocity() const { return velocity; }
43
44         geometry::Vector<int> &SpriteOffset() { return spriteOffset; }
45         const geometry::Vector<int> &SpriteOffset() const { return spriteOffset; }
46
47         void SetAnimation(const graphics::Animation *a);
48         void StartAnimation(app::Application &ctrl);
49         void StartAnimation(app::State &ctrl);
50         void StopAnimation();
51         bool AnimationRunning() const { return runner.Running(); }
52
53         void SetOrientation(Orientation);
54         Orientation GetOrientation() const { return orientation; }
55         void SetSpeed(float);
56
57         void SetFlags(int f) { flags = f; }
58         bool Blocking() const { return !(flags & FLAG_NONBLOCKING); }
59         bool Hostile() const {
60                 // NOTE: this is a stub for testing!
61                 return Blocking();
62         }
63
64         Entity *Follower() { return follower; }
65         const Entity *Follower() const { return follower; }
66         void AddFollower(Entity *);
67         void RemoveFollower(Entity *);
68
69         bool TileLock(const geometry::Vector<int> &tileSize) const;
70
71         void Update(float deltaT);
72
73         void Render(SDL_Surface *, const geometry::Vector<int> &offset) const;
74
75         static void CreateTypeDescription();
76         static void Construct(void *);
77         static void Load(void *);
78
79 private:
80         void UpdateVelocity();
81
82 private:
83         Entity *follower;
84         const graphics::Animation *animation;
85         graphics::AnimationRunner runner;
86         geometry::Vector<int> spriteOffset;
87         geometry::Vector<float> position;
88         geometry::Vector<float> velocity;
89         Orientation orientation;
90         float speed;
91         int flags;
92
93 };
94
95 }
96
97 #endif /* MAP_ENTITY_H_ */