-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.cpp
More file actions
66 lines (52 loc) · 884 Bytes
/
Input.cpp
File metadata and controls
66 lines (52 loc) · 884 Bytes
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
#include "Input.h"
void Input::Start()
{
_input = 0;
_lastInput = 0;
_isShift = false;
}
void Input::Update()
{
_lastInput = _input;
_input = _getch();
if (_input == -32)
_input = -_getch();
_isShift = _input >= 0 ? std::isupper(_input) : false;
if (_input >= 0)
_input = std::tolower(_input);
}
void Input::Clear()
{
Start();
}
bool Input::GetKeyPress(char key)
{
return _input == key;
}
bool Input::GetKeyDown(char key)
{
return _lastInput != key && _input == key;
}
bool Input::GetKeyUp(char key)
{
return _lastInput == key && _input != key;
}
bool Input::IsShift()
{
return _isShift;
}
float Input::GetVirtualAxis(char positiveKey, char negativeKey)
{
float axis;
if (Input::GetKeyPress(positiveKey))
axis = 1;
else if (Input::GetKeyPress(negativeKey))
axis = -1;
else
axis = 0;
return axis;
}
char Input::GetInput()
{
return _input;
}