Work on game input
This commit is contained in:
parent
89e9002b5e
commit
3c733cd490
|
@ -14,4 +14,17 @@ enum class Action
|
||||||
PRESS_SLIDER_LEFT, RELEASE_SLIDER_LEFT
|
PRESS_SLIDER_LEFT, RELEASE_SLIDER_LEFT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class Button
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
|
||||||
|
UP,
|
||||||
|
RIGHT,
|
||||||
|
DOWN,
|
||||||
|
LEFT,
|
||||||
|
|
||||||
|
SLIDER_RIGHT,
|
||||||
|
SLIDER_LEFT
|
||||||
|
};
|
||||||
|
|
||||||
#endif // CLASSICACTIONS_H
|
#endif // CLASSICACTIONS_H
|
||||||
|
|
|
@ -1,6 +1,95 @@
|
||||||
#include "classicgame.h"
|
#include "classicgame.h"
|
||||||
|
#include "classicinputtype.h"
|
||||||
|
|
||||||
ClassicGame::ClassicGame()
|
ClassicGame::ClassicGame()
|
||||||
|
{
|
||||||
|
_keys_to_buttons =
|
||||||
|
{
|
||||||
|
{sf::Keyboard::Up, Button::UP}, // Load from settings
|
||||||
|
{sf::Keyboard::Right, Button::RIGHT},
|
||||||
|
{sf::Keyboard::Down, Button::DOWN},
|
||||||
|
{sf::Keyboard::Left, Button::LEFT},
|
||||||
|
|
||||||
|
{sf::Keyboard::W, Button::UP},
|
||||||
|
{sf::Keyboard::D, Button::RIGHT},
|
||||||
|
{sf::Keyboard::S, Button::DOWN},
|
||||||
|
{sf::Keyboard::A, Button::LEFT},
|
||||||
|
|
||||||
|
{sf::Keyboard::E, Button::SLIDER_RIGHT},
|
||||||
|
{sf::Keyboard::Q, Button::SLIDER_LEFT}
|
||||||
|
};
|
||||||
|
|
||||||
|
_buttons_to_pressed_actions=
|
||||||
|
{
|
||||||
|
{Button::UP, Action::PRESS_UP},
|
||||||
|
{Button::RIGHT, Action::PRESS_RIGHT},
|
||||||
|
{Button::DOWN, Action::PRESS_DOWN},
|
||||||
|
{Button::LEFT, Action::PRESS_LEFT},
|
||||||
|
|
||||||
|
{Button::SLIDER_RIGHT, Action::PRESS_SLIDER_RIGHT},
|
||||||
|
{Button::SLIDER_LEFT, Action::PRESS_SLIDER_LEFT}
|
||||||
|
};
|
||||||
|
|
||||||
|
_buttons_to_released_actions=
|
||||||
|
{
|
||||||
|
{Button::UP, Action::RELEASE_UP},
|
||||||
|
{Button::RIGHT, Action::RELEASE_RIGHT},
|
||||||
|
{Button::DOWN, Action::RELEASE_DOWN},
|
||||||
|
{Button::LEFT, Action::RELEASE_LEFT},
|
||||||
|
|
||||||
|
{Button::SLIDER_RIGHT, Action::RELEASE_SLIDER_RIGHT},
|
||||||
|
{Button::SLIDER_LEFT, Action::RELEASE_SLIDER_LEFT}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClassicGame::run()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClassicGame::input(const sf::Event& event)
|
||||||
|
{
|
||||||
|
Action new_action = Action::NONE;
|
||||||
|
microsec timestamp = 0; /* 0 is temp. get from timeline */
|
||||||
|
|
||||||
|
switch (event.type)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
case sf::Event::KeyPressed:
|
||||||
|
{
|
||||||
|
if (_keys_to_buttons.find(event.key.code) != _keys_to_buttons.end())
|
||||||
|
new_action = getActionKeyPressed(_keys_to_buttons[event.key.code]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case sf::Event::KeyReleased:
|
||||||
|
{
|
||||||
|
if (_keys_to_buttons.find(event.key.code) != _keys_to_buttons.end())
|
||||||
|
new_action = getActionKeyReleased(_keys_to_buttons[event.key.code]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassicInputType input(timestamp, new_action);
|
||||||
|
/* Here get active Note from timeline and pass the input object to it */
|
||||||
|
}
|
||||||
|
|
||||||
|
Action ClassicGame::getActionKeyPressed(Button button) const
|
||||||
|
{
|
||||||
|
return _buttons_to_pressed_actions.at(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
Action ClassicGame::getActionKeyReleased(Button button) const
|
||||||
|
{
|
||||||
|
return _buttons_to_released_actions.at(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClassicGame::update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClassicGame::draw(const sf::RenderWindow& window) const
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,30 @@
|
||||||
#ifndef CLASSICGAME_H
|
#ifndef CLASSICGAME_H
|
||||||
#define CLASSICGAME_H
|
#define CLASSICGAME_H
|
||||||
|
|
||||||
#include "game.h"
|
#include <map>
|
||||||
|
|
||||||
class ClassicGame : public Game
|
#include "game.h"
|
||||||
|
#include "classicactions.h"
|
||||||
|
|
||||||
|
class ClassicGame final : public Game
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ClassicGame();
|
explicit ClassicGame();
|
||||||
virtual ~ClassicGame() override;
|
virtual ~ClassicGame() override = default;
|
||||||
|
|
||||||
virtual void run() override;
|
virtual void run() override;
|
||||||
|
|
||||||
virtual void input(const sf::Event& event) override;
|
virtual void input(const sf::Event& event) override;
|
||||||
virtual void update() override;
|
virtual void update() override;
|
||||||
virtual void draw(const sf::RenderWindow& window) const override;
|
virtual void draw(const sf::RenderWindow& window) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<sf::Keyboard::Key, Button> _keys_to_buttons;
|
||||||
|
std::map<Button, Action> _buttons_to_pressed_actions;
|
||||||
|
std::map<Button, Action> _buttons_to_released_actions;
|
||||||
|
|
||||||
|
Action getActionKeyPressed(Button button) const;
|
||||||
|
Action getActionKeyReleased(Button button) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLASSICGAME_H
|
#endif // CLASSICGAME_H
|
||||||
|
|
|
@ -15,5 +15,6 @@ bool ClassicInputType::operator==(const Action& comparing_action) const
|
||||||
|
|
||||||
bool ClassicInputType::operator==(const ClassicInputType& comparing_action) const
|
bool ClassicInputType::operator==(const ClassicInputType& comparing_action) const
|
||||||
{
|
{
|
||||||
return _action == comparing_action._action;
|
return _action == comparing_action._action
|
||||||
|
&& _button == comparing_action._button;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Action _action;
|
Action _action;
|
||||||
|
Button _button;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLASSICINPUTTYPE_H
|
#endif // CLASSICINPUTTYPE_H
|
||||||
|
|
Loading…
Reference in New Issue