-
Notifications
You must be signed in to change notification settings - Fork 0
/
Input.cpp
97 lines (89 loc) · 1.93 KB
/
Input.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "Input.h"
bool Input::isSet = false;
eDirections Input::input_dir(sf::Event event)
{
eDirections dir;
static bool pressedLeft, pressedRight;
static bool* pressedLater;
if (!isSet)
{
pressedLeft = false;
pressedRight = false;
pressedLater = &pressedLeft;
dir = stop;
isSet = true;
}
if (event.type == sf::Event::KeyPressed)
{
switch (event.key.code)
{
case sf::Keyboard::Left:
pressedLeft = true;
pressedLater = &pressedLeft;
break;
case sf::Keyboard::Right:
pressedRight = true;
pressedLater = &pressedRight;
break;
default:
break;
}
}
else if (event.type == sf::Event::KeyReleased)
{
switch (event.key.code)
{
case sf::Keyboard::Left:
pressedLeft = false;
break;
case sf::Keyboard::Right:
pressedRight = false;
break;
default:
break;
}
}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space))
//{
// sf::sleep(sf::milliseconds(30));
// while (!(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space)))
// ; // wait until space is pressed again
//}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
return backToMenu;
if (*pressedLater == true)
{
if (pressedLater == &pressedLeft)
dir = left;
else if (pressedLater == &pressedRight)
dir = right;
}
else
{
if (pressedLeft)
dir = left;
else if (pressedRight)
dir = right;
else
dir = stop;
}
return dir;
}
char Input::user_input_key(sf::Event event)
{
char input = '\0';
if (event.type == sf::Event::KeyPressed)
{
switch (event.key.code)
{
case sf::Keyboard::Left: input = '4'; break;
case sf::Keyboard::Right: input = '6'; break;
case sf::Keyboard::Up: input = '8'; break;
case sf::Keyboard::Down: input = '2'; break;
case sf::Keyboard::Enter: input = '\n'; break;
case sf::Keyboard::Space: input = ' '; break;
default: break;
}
}
return input;
}