From: Daniel Karbach Date: Sun, 30 Sep 2012 14:26:13 +0000 (+0200) Subject: plugged entities into map state X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=a550d5e73bef77a8bb98a31034dcaad83a43677a;p=l2e.git plugged entities into map state --- diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index ed77648..7f602a7 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,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::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(); } } diff --git a/src/map/MapState.h b/src/map/MapState.h index 96a5c22..e180d48 100644 --- a/src/map/MapState.h +++ b/src/map/MapState.h @@ -8,11 +8,14 @@ #ifndef MAP_MAPSTATE_H_ #define MAP_MAPSTATE_H_ +#include "Entity.h" #include "fwd.h" #include "../app/State.h" #include "../geometry/Vector.h" #include "../graphics/Camera.h" +#include + namespace map { class MapState @@ -33,10 +36,19 @@ public: virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); +public: + void AddEntity(Entity *e) { entities.push_back(e); } + void ControlEntity(Entity *e) { controlled = e; camera.SetTarget(&e->Position()); } + +private: + static bool ZCompare(const Entity *lhs, const Entity *rhs); + private: const Map *map; - geometry::Vector tempTarget; + Entity *controlled; + geometry::Vector tempTarget; graphics::Camera camera; + std::vector entities; };