]> git.localhorst.tv Git - l2e.git/blob - src/map/Entity.h
92b1b7cf1a4ccf6cff5d3b8776ab35cd6594ba84
[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<float> &SpriteOffset() { return spriteOffset; }
45         const geometry::Vector<float> &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
60         Entity *Follower() { return follower; }
61         const Entity *Follower() const { return follower; }
62         void AddFollower(Entity *);
63         void RemoveFollower(Entity *);
64
65         bool TileLock(const geometry::Vector<int> &tileSize) const;
66
67         void Update(float deltaT);
68
69         void Render(SDL_Surface *, const geometry::Vector<int> &offset) const;
70
71 private:
72         void UpdateVelocity();
73
74 private:
75         Entity *follower;
76         const graphics::Animation *animation;
77         graphics::AnimationRunner runner;
78         geometry::Vector<float> spriteOffset;
79         geometry::Vector<float> position;
80         geometry::Vector<float> velocity;
81         Orientation orientation;
82         float speed;
83         int flags;
84
85 };
86
87 }
88
89 #endif /* MAP_ENTITY_H_ */