]> git.localhorst.tv Git - l2e.git/blobdiff - src/map/MapState.cpp
plugged entities into map state
[l2e.git] / src / map / MapState.cpp
index ed776482e3763084308af422cfe31766787cca1b..7f602a73ebf01c0d7f5ac338e2c22c30fc7d236a 100644 (file)
@@ -11,6 +11,8 @@
 #include "../app/Application.h"
 #include "../app/Input.h"
 
+#include <algorithm>
+
 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,28 @@ void MapState::Resize(int width, int height) {
 
 
 void MapState::HandleEvents(const Input &input) {
-
+       if (!controlled) return;
 }
 
 void MapState::UpdateWorld(float deltaT) {
-
+       for (std::vector<Entity *>::iterator i(entities.begin()), end(entities.end()); i != end; ++i) {
+               (*i)->Update(deltaT);
+       }
 }
 
 void MapState::Render(SDL_Surface *screen) {
        Vector<int> offset(camera.CalculateOffset());
        map->Render(screen, offset);
+
+       std::sort(entities.begin(), entities.end(), ZCompare);
+       for (std::vector<Entity *>::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();
 }
 
 }