]> git.localhorst.tv Git - l2e.git/blob - src/map/MapState.cpp
added test entity
[l2e.git] / src / map / MapState.cpp
1 /*
2  * MapState.cpp
3  *
4  *  Created on: Sep 29, 2012
5  *      Author: holy
6  */
7
8 #include "MapState.h"
9
10 #include "Map.h"
11 #include "../app/Application.h"
12 #include "../app/Input.h"
13
14 #include <algorithm>
15
16 using app::Application;
17 using app::Input;
18 using geometry::Vector;
19
20 namespace map {
21
22 MapState::MapState(const Map *map)
23 : map(map)
24 , controlled(0)
25 , tempTarget(20, 20)
26 , camera(100, 100, &tempTarget) {
27
28 }
29
30
31 void MapState::EnterState(Application &ctrl, SDL_Surface *screen) {
32         camera.Resize(screen->w, screen->h);
33 }
34
35 void MapState::ExitState(Application &ctrl, SDL_Surface *screen) {
36
37 }
38
39 void MapState::ResumeState(Application &ctrl, SDL_Surface *screen) {
40         camera.Resize(screen->w, screen->h);
41 }
42
43 void MapState::PauseState(Application &ctrl, SDL_Surface *screen) {
44
45 }
46
47 void MapState::Resize(int width, int height) {
48         camera.Resize(width, height);
49 }
50
51
52 void MapState::HandleEvents(const Input &input) {
53         if (!controlled) return;
54 }
55
56 void MapState::UpdateWorld(float deltaT) {
57         for (std::vector<Entity *>::iterator i(entities.begin()), end(entities.end()); i != end; ++i) {
58                 (*i)->Update(deltaT);
59         }
60 }
61
62 void MapState::Render(SDL_Surface *screen) {
63         Vector<int> offset(camera.CalculateOffset());
64         map->Render(screen, offset);
65
66         std::sort(entities.begin(), entities.end(), ZCompare);
67         for (std::vector<Entity *>::iterator i(entities.begin()), end(entities.end()); i != end; ++i) {
68                 (*i)->Render(screen, offset);
69         }
70 }
71
72
73 bool MapState::ZCompare(const Entity *lhs, const Entity *rhs) {
74         return lhs->Position().Y() < rhs->Position().Y();
75 }
76
77 }