-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.cpp
More file actions
36 lines (31 loc) · 691 Bytes
/
Input.cpp
File metadata and controls
36 lines (31 loc) · 691 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
#include "Input.h"
Input::Input()
{
for (int key{ 0 }; key < sf::Keyboard::KeyCount; ++key)
keyStateMap[key] = KeyState::RELEASED;
}
void Input::Frame()
{
for (int key{ 0 }; key < sf::Keyboard::KeyCount; ++key)
{
if (keyStateMap[key] == KeyState::PRESSED)
keyStateMap[key] = KeyState::DOWN;
}
}
void Input::OnKeyDown(sf::Keyboard::Key key)
{
if (keyStateMap[key] != KeyState::DOWN)
keyStateMap[key] = KeyState::PRESSED;
}
void Input::OnKeyUp(sf::Keyboard::Key key)
{
keyStateMap[key] = KeyState::RELEASED;
}
bool Input::IsKeyPressed(int key)
{
return keyStateMap[key] == KeyState::PRESSED;
}
bool Input::IsKeyDown(int key)
{
return keyStateMap[key] == KeyState::DOWN;
}