X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FMapState.cpp;h=6ef2be748deb8e1dc874e3588f0b4326f561aa8a;hb=1d6a9f01b8db0f5212b6a02603dd0670c6da38c7;hp=ed776482e3763084308af422cfe31766787cca1b;hpb=dc7b19b8d0be4aff410f9c4514c742fe28b25ff4;p=l2e.git diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index ed77648..6ef2be7 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,8 +21,10 @@ namespace map { MapState::MapState(const Map *map) : map(map) +, controlled(0) , tempTarget(20, 20) -, camera(100, 100, &tempTarget) { +, camera(100, 100, &tempTarget) +, walkingSpeed(64) { } @@ -47,16 +51,47 @@ 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; + + if (input.IsDown(Input::PAD_UP)) { + controlled->SetOrientation(Entity::ORIENTATION_NORTH); + controlled->SetSpeed(walkingSpeed); + } else if (input.IsDown(Input::PAD_RIGHT)) { + controlled->SetOrientation(Entity::ORIENTATION_EAST); + controlled->SetSpeed(walkingSpeed); + } else if (input.IsDown(Input::PAD_DOWN)) { + controlled->SetOrientation(Entity::ORIENTATION_SOUTH); + controlled->SetSpeed(walkingSpeed); + } else if (input.IsDown(Input::PAD_LEFT)) { + controlled->SetOrientation(Entity::ORIENTATION_WEST); + controlled->SetSpeed(walkingSpeed); + } else { + controlled->SetSpeed(0.0f); + } } 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) { + SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); + 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(); } }