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;
56 void MapState::UpdateWorld(float deltaT) {
57 for (std::vector<Entity *>::iterator i(entities.begin()), end(entities.end()); i != end; ++i) {
62 void MapState::Render(SDL_Surface *screen) {
63 Vector<int> offset(camera.CalculateOffset());
64 map->Render(screen, offset);
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);
73 bool MapState::ZCompare(const Entity *lhs, const Entity *rhs) {
74 return lhs->Position().Y() < rhs->Position().Y();