From d9f829f10a8310f53d945cd96ecce28193b792d8 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 26 Sep 2014 01:42:49 +0200 Subject: Add support for interactions with entities --- src/control/MapContext.cpp | 13 +++++++++++++ src/control/MapContext.hpp | 1 + 2 files changed, 14 insertions(+) (limited to 'src/control') diff --git a/src/control/MapContext.cpp b/src/control/MapContext.cpp index f5d4c05..1b0e721 100644 --- a/src/control/MapContext.cpp +++ b/src/control/MapContext.cpp @@ -71,6 +71,15 @@ void MapContext::movePlayerContinue(uint64_t time) { movePlayer(Model::Direction::WEST, time); } +void MapContext::interact(uint64_t time) { + Model::Position p = map.getEntityPosition(playerEntity) + playerEntity->getDirection(); + Model::Entity *target = map.getEntityAt(p); + + if (!target) + return; + + target->interact(time); +} void MapContext::keyPressed(uint16_t key, uint64_t time) { switch (key) { @@ -88,6 +97,10 @@ void MapContext::keyPressed(uint16_t key, uint64_t time) { case SDL_SCANCODE_LEFT: movePlayer(Model::Direction::WEST, time); + break; + + case SDL_SCANCODE_SPACE: + interact(time); } } diff --git a/src/control/MapContext.hpp b/src/control/MapContext.hpp index 05ed991..18d4cfe 100644 --- a/src/control/MapContext.hpp +++ b/src/control/MapContext.hpp @@ -52,6 +52,7 @@ private: void movePlayer(Model::Direction dir, uint64_t time); void movePlayerContinue(uint64_t time); void keyPressed(uint16_t key, uint64_t time); + void interact(uint64_t time); Model::Position getViewPosition(uint64_t time) { return map.getEntityPosition(playerEntity, time); -- cgit v1.2.3