diff --git a/CMakeLists.txt b/CMakeLists.txt index eb17f94..a286571 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,12 @@ set(SOURCES src/game/input/input_mapper.cpp src/game/input/input_mapper.h src/game/input/action_controller.cpp - src/game/input/action_controller.h src/game/input/direction.h src/game/input/direction.cpp) + src/game/input/action_controller.h + src/game/input/direction.h + src/game/input/direction.cpp + src/game/player/player.cpp + src/game/player/player.hpp + src/game/input/game_inputs.hpp) set(PHYSICS_00_SOURCES src/prototypes/physics_00.cpp) diff --git a/src/game/game.cpp b/src/game/game.cpp index fa833da..26cf66d 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -3,17 +3,18 @@ #include #include "game.h" -#include "../config.h" Game::Game(std::shared_ptr window) : window(std::move(window)), gameObjects(), - actionController(new ActionController(this)), - inputMapper(new InputMapper(this)) + actionController(new ActionController(this)) { + InputMapper::setGame(this); } Game::~Game() { + delete actionController; + for (auto &gameObject: gameObjects) { delete gameObject; @@ -28,14 +29,14 @@ void Game::run() while (window->isOpen()) { - inputMapper->processEvents(); + InputMapper::processEvents(); TimeSinceLastUpdate += clock.restart(); while (TimeSinceLastUpdate >= FRAME_TIME) { TimeSinceLastUpdate -= FRAME_TIME; update(); - inputMapper->processEvents(); + InputMapper::processEvents(); } drawFrame(); } diff --git a/src/game/game.h b/src/game/game.h index 72ca7fc..e4bf7b4 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -10,7 +10,6 @@ class ActionController; -class InputMapper; class Game @@ -28,7 +27,6 @@ public: std::shared_ptr window; ActionController *actionController; - InputMapper *inputMapper; private: std::vector gameObjects; diff --git a/src/game/input/game_inputs.hpp b/src/game/input/game_inputs.hpp new file mode 100644 index 0000000..313d7d3 --- /dev/null +++ b/src/game/input/game_inputs.hpp @@ -0,0 +1,25 @@ +#ifndef HOLESOME_GAME_INPUTS_HPP +#define HOLESOME_GAME_INPUTS_HPP + + +enum MenuInputs +{ + MENU_NONE, + MENU_UP, + MENU_DOWN, + MENU_LEFT, + MENU_RIGHT, + MENU_SELECT, + MENU_BACK, + MENU_OPEN +}; + +enum GameInputs +{ + GAME_NONE, + GAME_HIDE, + GAME_MOVE, + GAME_RUN +}; + +#endif //HOLESOME_GAME_INPUTS_HPP diff --git a/src/game/input/input_mapper.cpp b/src/game/input/input_mapper.cpp index be863b0..2960e6c 100644 --- a/src/game/input/input_mapper.cpp +++ b/src/game/input/input_mapper.cpp @@ -1,11 +1,12 @@ #include "input_mapper.h" -InputMapper::InputMapper(Game *game) : game(game) +void InputMapper::setGame(Game *game) { - + InputMapper::game = game; } + void InputMapper::processEvents() { sf::Event event{}; diff --git a/src/game/input/input_mapper.h b/src/game/input/input_mapper.h index 8fc61c8..3980104 100644 --- a/src/game/input/input_mapper.h +++ b/src/game/input/input_mapper.h @@ -13,14 +13,14 @@ class Game; class InputMapper { public: - explicit InputMapper(Game *game); + static void setGame(Game *game); - void processEvents(); + static void processEvents(); private: - Game *game; + static inline Game *game = nullptr; - void handleKeyPress(sf::Event::KeyEvent event); + static void handleKeyPress(sf::Event::KeyEvent event); }; diff --git a/src/game/player/player.cpp b/src/game/player/player.cpp new file mode 100644 index 0000000..5015568 --- /dev/null +++ b/src/game/player/player.cpp @@ -0,0 +1 @@ +#include "player.hpp" diff --git a/src/game/player/player.hpp b/src/game/player/player.hpp new file mode 100644 index 0000000..e02e668 --- /dev/null +++ b/src/game/player/player.hpp @@ -0,0 +1,19 @@ +#ifndef HOLESOME_PLAYER_HPP +#define HOLESOME_PLAYER_HPP + +#include "../game_object.h" + +class Player : GameObject +{ +public: + Player(); + + ~Player(); + + void draw(sf::RenderWindow *window) const override; + + void update() const override; +}; + + +#endif //HOLESOME_PLAYER_HPP