X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FMapState.cpp;h=5477999899905d2015e99d4afe96a30ff07b90c0;hb=657eed00ae73b8d06470cec0d955aeada537a90d;hp=ed776482e3763084308af422cfe31766787cca1b;hpb=dc7b19b8d0be4aff410f9c4514c742fe28b25ff4;p=l2e.git diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index ed77648..5477999 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -11,6 +11,8 @@ #include "../app/Application.h" #include "../app/Input.h" +#include + using app::Application; using app::Input; using geometry::Vector; @@ -19,6 +21,7 @@ namespace map { MapState::MapState(const Map *map) : map(map) +, controlled(0) , tempTarget(20, 20) , camera(100, 100, &tempTarget) { @@ -47,16 +50,29 @@ void MapState::Resize(int width, int height) { void MapState::HandleEvents(const Input &input) { - + if (!controlled) return; + if (!controlled->TileLock(map->Tileset()->Width(), map->Tileset()->Height())) return; } void MapState::UpdateWorld(float deltaT) { - + for (std::vector::iterator i(entities.begin()), end(entities.end()); i != end; ++i) { + (*i)->Update(deltaT); + } } void MapState::Render(SDL_Surface *screen) { Vector offset(camera.CalculateOffset()); map->Render(screen, offset); + + std::sort(entities.begin(), entities.end(), ZCompare); + for (std::vector::iterator i(entities.begin()), end(entities.end()); i != end; ++i) { + (*i)->Render(screen, offset); + } +} + + +bool MapState::ZCompare(const Entity *lhs, const Entity *rhs) { + return lhs->Position().Y() < rhs->Position().Y(); } }