-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.hpp
42 lines (36 loc) · 1016 Bytes
/
input.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef INPUT_HPP // include guard
#define INPUT_HPP
#include <map>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
class InputState
{
public:
std::map<std::string, bool> keys;
InputState()
{
keys["W"] = false;
keys["A"] = false;
keys["S"] = false;
keys["D"] = false;
keys["Left"] = false;
keys["Right"] = false;
keys["Escape"] = false;
};
void update()
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
keys["W"] = true;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
keys["A"] = true;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
keys["S"] = true;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
keys["D"] = true;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
keys["Left"] = true;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
keys["Right"] = true;
};
};
#endif /* INPUT_HPP */