Peoplemon  0.1.0
Peoplemon 3 game source documentation
Control.cpp
Go to the documentation of this file.
1 #include <Core/Input/Control.hpp>
2 
3 namespace core
4 {
5 namespace input
6 {
7 void configureInputSystem(bl::input::InputSystem& system) {
8  // register controls
9  system.setControlCount(Control::Count);
10  system.configureTriggerControl(Control::MoveUp);
11  system.configureTriggerControl(Control::MoveRight);
12  system.configureTriggerControl(Control::MoveDown);
13  system.configureTriggerControl(Control::MoveLeft);
14  system.configureTriggerControl(Control::Sprint);
15  system.configureTriggerControl(Control::Interact);
16  system.configureTriggerControl(Control::Pause);
17  system.configureTriggerControl(Control::Back);
18 
19  // creator the actor. Peoplemon is only 1 player locally
20  bl::input::Actor& user = system.addActor();
21 
22  // set keyboard and mouse defaults. no defaults for controller
23  user.getKBMTriggerControl(Control::MoveUp).triggerOnKey(sf::Keyboard::W);
24  user.getKBMTriggerControl(Control::MoveRight).triggerOnKey(sf::Keyboard::D);
25  user.getKBMTriggerControl(Control::MoveDown).triggerOnKey(sf::Keyboard::S);
26  user.getKBMTriggerControl(Control::MoveLeft).triggerOnKey(sf::Keyboard::A);
27  user.getKBMTriggerControl(Control::Sprint).triggerOnKey(sf::Keyboard::LShift);
28  user.getKBMTriggerControl(Control::Interact).triggerOnKey(sf::Keyboard::Space);
29  user.getKBMTriggerControl(Control::Pause).triggerOnKey(sf::Keyboard::Enter);
30  user.getKBMTriggerControl(Control::Back).triggerOnKey(sf::Keyboard::LControl);
31 
32  // load user preferences from config
33  system.loadFromConfig();
34 }
35 
36 EntityControl fromDirection(bl::tmap::Direction dir) {
37  switch (dir) {
38  case bl::tmap::Direction::Up:
39  return Control::MoveUp;
40  case bl::tmap::Direction::Right:
41  return Control::MoveRight;
42  case bl::tmap::Direction::Down:
43  return Control::MoveDown;
44  case bl::tmap::Direction::Left:
45  default:
46  return Control::MoveLeft;
47  }
48 }
49 
50 } // namespace input
51 } // namespace core
Core classes and functionality for both the editor and game.
void configureInputSystem(bl::input::InputSystem &system)
Configures the input system for the set of peoplemon inputs.
Definition: Control.cpp:7
std::underlying_type_t< Control::EntityControl > EntityControl
Helper typedef to avoid too much casting boilerplate.
Definition: Control.hpp:44
EntityControl fromDirection(bl::tmap::Direction direction)
Helper method to convert a move direction to a control.
Definition: Control.cpp:36