]> git.localhorst.tv Git - l2e.git/blob - src/map/MapState.h
extracted map loading/unloading
[l2e.git] / src / map / MapState.h
1 /*
2  * MapState.h
3  *
4  *  Created on: Sep 29, 2012
5  *      Author: holy
6  */
7
8 #ifndef MAP_MAPSTATE_H_
9 #define MAP_MAPSTATE_H_
10
11 #include "Entity.h"
12 #include "fwd.h"
13 #include "../app/State.h"
14 #include "../geometry/Vector.h"
15 #include "../graphics/Camera.h"
16
17 #include <vector>
18
19 namespace map {
20
21 class MapState
22 : public app::State {
23
24 public:
25         explicit MapState(Map *);
26         virtual ~MapState() { }
27
28 public:
29         virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
30         virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
31         virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
32         virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
33         virtual void Resize(int width, int height);
34
35         virtual void HandleEvents(const app::Input &);
36         virtual void UpdateWorld(float 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(float s) { walkingSpeed = s; }
44
45         void Transition(Map *, const geometry::Vector<int> &coordinates);
46
47 private:
48         static bool ZCompare(const Entity *lhs, const Entity *rhs);
49
50         void UnloadMap();
51         void LoadMap(Map *);
52
53         bool CheckBlocking() const;
54
55         void OnTileLock();
56         void OnGridLock();
57         void OnMove(bool);
58
59         void UpdateFollower(Entity &);
60         void StopFollowers(Entity &);
61
62         void LockEntities();
63         void CheckMonster();
64         void CheckTrigger();
65
66 private:
67         Map *map;
68         Entity *controlled;
69         app::Timer<float> moveTimer;
70         geometry::Vector<float> tempTarget;
71         geometry::Vector<int> lastLock;
72         graphics::Camera camera;
73         std::vector<Entity *> entities;
74         float walkingSpeed;
75         int nextDirection;
76         bool afterLock;
77         bool skipLock;
78         bool debug;
79
80 };
81
82 }
83
84 #endif /* MAP_MAPSTATE_H_ */