]> git.localhorst.tv Git - l2e.git/blob - src/map/MapState.h
implemented map tile anmation
[l2e.git] / src / map / MapState.h
1 #ifndef MAP_MAPSTATE_H_
2 #define MAP_MAPSTATE_H_
3
4 namespace common {
5         struct GameConfig;
6 }
7 namespace map {
8         class Map;
9         class Trigger;
10 }
11
12 #include "Entity.h"
13 #include "../app/State.h"
14 #include "../app/Timer.h"
15 #include "../common/ScriptHost.h"
16 #include "../common/ScriptRunner.h"
17 #include "../math/Fixed.h"
18 #include "../math/Vector.h"
19 #include "../graphics/Camera.h"
20
21 #include <vector>
22
23 namespace map {
24
25 /// Shows a map and its entities an optionally control a single entity.
26 class MapState
27 : public app::State
28 , public common::ScriptHost {
29
30 public:
31         explicit MapState(common::GameConfig *, Map *);
32         virtual ~MapState() { }
33
34 public:
35         virtual void HandleEvents(const app::Input &);
36         virtual void UpdateWorld(Uint32 deltaT);
37         virtual void Render(SDL_Surface *);
38
39 public:
40         void AddEntity(Entity *e) { entities.push_back(e); }
41         void ControlEntity(Entity *e) { controlled = e; camera.SetTarget(&e->Position()); }
42
43         void SetWalkingSpeed(math::Fixed<8> s) { walkingSpeed = s; }
44
45         void Transition(Map *, const math::Vector<int> &coordinates);
46
47         virtual void HandleSyscall(common::ScriptRunner &);
48
49 private:
50         virtual void OnEnterState(SDL_Surface *screen);
51         virtual void OnExitState(SDL_Surface *screen);
52         virtual void OnResumeState(SDL_Surface *screen);
53         virtual void OnPauseState(SDL_Surface *screen);
54
55         virtual void OnResize(int width, int height);
56
57 private:
58         static bool ZCompare(const Entity *lhs, const Entity *rhs);
59
60         void UnloadMap();
61         void LoadMap(Map *);
62
63         bool CheckBlocking();
64         bool CheckBlocking(const math::Vector<int> &position, Entity::Orientation direction) const;
65
66         void OnTileLock();
67         bool OnGridLock();
68         void OnMove(bool);
69
70         void UpdateFollower(Entity &);
71         void StopFollowers(Entity &);
72
73         void LockEntities();
74         bool CheckMonster();
75         void LoadBattle(Entity &hero, Entity &monster);
76
77         bool CheckLockTrigger();
78         bool CheckMoveTrigger();
79         void RunTrigger(Trigger &);
80
81         enum Syscalls {
82                 TRANSITION = 1,
83                 WARP = 2,
84         };
85
86 private:
87         common::GameConfig *game;
88         Map *map;
89         Entity *controlled;
90         Entity *pushed;
91         common::ScriptRunner runner;
92         app::Timer<Uint32> moveTimer;
93         math::Vector<int> lastLock;
94         graphics::Camera camera;
95         std::vector<Entity *> entities;
96         math::Fixed<8> walkingSpeed;
97         app::Timer<Uint32> tileAnimation;
98         int nextDirection;
99         bool afterLock;
100         bool skipLock;
101         bool pushing;
102         bool debug;
103
104 };
105
106 }
107
108 #endif