From d41e2dae45e08059e23041f0146b91add0c2cace Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 23 Sep 2014 02:11:11 +0200 Subject: Add transitions for entity movement --- src/control/MapContext.cpp | 30 ++++++++++++++++++++++++++++++ src/control/MapContext.hpp | 20 +------------------- 2 files changed, 31 insertions(+), 19 deletions(-) (limited to 'src/control') diff --git a/src/control/MapContext.cpp b/src/control/MapContext.cpp index 5fda337..f4dd31e 100644 --- a/src/control/MapContext.cpp +++ b/src/control/MapContext.cpp @@ -45,6 +45,36 @@ MapContext::MapContext(ImageLoader *imageLoader0, const std::shared_ptrgetName()] = imageLoader->get("entity/" + entity->getName()); } +void MapContext::advance(InputHandler *inputHandler, uint32_t ticks) { + uint64_t totalTicksOld = totalTicks; + totalTicks += ticks; + + unsigned advance = totalTicks - totalTicksOld; + + while (advance) { + advance = map->getPlayerEntity().advance(advance); + + if (map->getPlayerEntity().hasTransition()) + break; + + if (inputHandler->isKeyPressed(SDL_SCANCODE_UP)) { + map->getPlayerEntity().move(Model::NORTH, 250); + } + else if (inputHandler->isKeyPressed(SDL_SCANCODE_RIGHT)) { + map->getPlayerEntity().move(Model::EAST, 250); + } + else if (inputHandler->isKeyPressed(SDL_SCANCODE_DOWN)) { + map->getPlayerEntity().move(Model::SOUTH, 250); + } + else if (inputHandler->isKeyPressed(SDL_SCANCODE_LEFT)) { + map->getPlayerEntity().move(Model::WEST, 250); + } + else { + break; + } + } +} + } } diff --git a/src/control/MapContext.hpp b/src/control/MapContext.hpp index 4cbf38a..504afc2 100644 --- a/src/control/MapContext.hpp +++ b/src/control/MapContext.hpp @@ -53,25 +53,7 @@ private: public: MapContext(ImageLoader *imageLoader0, const std::shared_ptr &map0); - void advance(InputHandler *inputHandler, uint32_t ticks) { - uint64_t totalTicksOld = totalTicks; - totalTicks += ticks; - - uint64_t advanced = totalTicks/100 - totalTicksOld/100; - - if (inputHandler->isKeyPressed(SDL_SCANCODE_UP)) { - map->getPlayerEntity().move(Model::NORTH, advanced); - } - else if (inputHandler->isKeyPressed(SDL_SCANCODE_RIGHT)) { - map->getPlayerEntity().move(Model::EAST, advanced); - } - else if (inputHandler->isKeyPressed(SDL_SCANCODE_DOWN)) { - map->getPlayerEntity().move(Model::SOUTH, advanced); - } - else if (inputHandler->isKeyPressed(SDL_SCANCODE_LEFT)) { - map->getPlayerEntity().move(Model::WEST, advanced); - } - } + void advance(InputHandler *inputHandler, unsigned ticks); std::shared_ptr initView(const std::shared_ptr &window) { return std::make_shared(window, map, tiles, entities); -- cgit v1.2.3