diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-23 00:13:05 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-23 00:13:05 +0200 |
commit | 11e77a9d65972c8e59aefd72419dfcf9036e9f6a (patch) | |
tree | 03288809e9a592849e881d6f3baae2eb41bee5cb /src/control/MapContext.hpp | |
parent | c9b41bc1022c75ac6da84f4fa503dd8231a96cf2 (diff) | |
download | rpgedit-11e77a9d65972c8e59aefd72419dfcf9036e9f6a.tar rpgedit-11e77a9d65972c8e59aefd72419dfcf9036e9f6a.zip |
Allow player movement
Diffstat (limited to 'src/control/MapContext.hpp')
-rw-r--r-- | src/control/MapContext.hpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/control/MapContext.hpp b/src/control/MapContext.hpp index a98d818..4cbf38a 100644 --- a/src/control/MapContext.hpp +++ b/src/control/MapContext.hpp @@ -27,6 +27,7 @@ #pragma once #include "ImageLoader.hpp" +#include "InputHandler.hpp" #include "../model/Map.hpp" #include "../view/MapView.hpp" @@ -47,9 +48,31 @@ private: std::vector<SDL_Surface *> tiles; std::map<std::string, SDL_Surface *> entities; + uint64_t totalTicks = 0; + public: MapContext(ImageLoader *imageLoader0, const std::shared_ptr<const Model::Map> &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); + } + } + std::shared_ptr<View::MapView> initView(const std::shared_ptr<View::Window> &window) { return std::make_shared<View::MapView>(window, map, tiles, entities); } |