From 93123e97251fc791c1cac193d675cce9a1ac2de6 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 3 Mar 2022 19:41:23 +0100 Subject: feat: add moving cursor --- src/game/game.cpp | 35 +++++++++++++++++++++++++++++++++-- src/game/game.hpp | 9 +++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) (limited to 'src/game') diff --git a/src/game/game.cpp b/src/game/game.cpp index 2b09470..ee3a2b8 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1,7 +1,12 @@ #include "game.hpp" -Game::Game(std::shared_ptr scene, std::shared_ptr input_handler) - : _scene(std::move(scene)), _input_handler(std::move(input_handler)) +#include + +Game::Game(std::shared_ptr scene, std::shared_ptr input_handler, + std::shared_ptr cursor_controller) + : _scene(std::move(scene)), + _input_handler(std::move(input_handler)), + _cursor_controller(std::move(cursor_controller)) { } @@ -22,6 +27,32 @@ void Game::run() exit(EXIT_SUCCESS); }); + auto cursor_controller = _cursor_controller; + + _input_handler->attach('k', + [&cursor_controller]() + { + cursor_controller->move(1U); + }); + + _input_handler->attach('j', + [&cursor_controller]() + { + cursor_controller->move(1U); + }); + + _input_handler->attach('h', + [&cursor_controller]() + { + cursor_controller->move(1U); + }); + + _input_handler->attach('l', + [&cursor_controller]() + { + cursor_controller->move(1U); + }); + _input_handler->listen(); _scene->leave(); diff --git a/src/game/game.hpp b/src/game/game.hpp index bc37c91..dd0d3c8 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -5,17 +5,22 @@ #include "interfaces/input.hpp" #include "interfaces/scene.hpp" +#include "engine/user/cursor.hpp" + #include -class Game : public IGame, public AutoWirable +class Game : public IGame, + public AutoWirable { public: explicit Game(std::shared_ptr scene, - std::shared_ptr input_handler); + std::shared_ptr input_handler, + std::shared_ptr cursor_controller); void run() override; private: std::shared_ptr _scene; std::shared_ptr _input_handler; + std::shared_ptr _cursor_controller; }; -- cgit v1.2.3-18-g5258