4 * Created on: Sep 29, 2012
11 #include "../app/Application.h"
12 #include "../app/Input.h"
16 using app::Application;
18 using geometry::Vector;
22 MapState::MapState(const Map *map)
26 , camera(100, 100, &tempTarget) {
31 void MapState::EnterState(Application &ctrl, SDL_Surface *screen) {
32 camera.Resize(screen->w, screen->h);
35 void MapState::ExitState(Application &ctrl, SDL_Surface *screen) {
39 void MapState::ResumeState(Application &ctrl, SDL_Surface *screen) {
40 camera.Resize(screen->w, screen->h);
43 void MapState::PauseState(Application &ctrl, SDL_Surface *screen) {
47 void MapState::Resize(int width, int height) {
48 camera.Resize(width, height);
52 void MapState::HandleEvents(const Input &input) {
53 if (!controlled) return;
54 if (!controlled->TileLock(map->Tileset()->Width(), map->Tileset()->Height())) return;
57 void MapState::UpdateWorld(float deltaT) {
58 for (std::vector<Entity *>::iterator i(entities.begin()), end(entities.end()); i != end; ++i) {
63 void MapState::Render(SDL_Surface *screen) {
64 Vector<int> offset(camera.CalculateOffset());
65 map->Render(screen, offset);
67 std::sort(entities.begin(), entities.end(), ZCompare);
68 for (std::vector<Entity *>::iterator i(entities.begin()), end(entities.end()); i != end; ++i) {
69 (*i)->Render(screen, offset);
74 bool MapState::ZCompare(const Entity *lhs, const Entity *rhs) {
75 return lhs->Position().Y() < rhs->Position().Y();