-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_manager.cpp
More file actions
64 lines (50 loc) · 1.16 KB
/
Copy pathinput_manager.cpp
File metadata and controls
64 lines (50 loc) · 1.16 KB
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
#include "input_manager.h"
#include "input_sdl.h"
static JoyState player1;
static JoyState player2;
static Byte JoyStateToByte(const JoyState& joy)
{
Byte d = 0xFF;
if (joy.up) d &= 0xFE;
if (joy.down) d &= 0xFB;
if (joy.left) d &= 0xF7;
if (joy.right) d &= 0xFD;
if (joy.fire) d &= 0xEF;
return d;
}
void InputManager_HandleEvent(const SDL_Event& event)
{
InputSDL_HandleEvent(event);
}
void InputManager_SetPlayer1State(const JoyState& state)
{
player1 = state;
}
void InputManager_SetPlayer2State(const JoyState& state)
{
player2 = state;
}
JoyState InputManager_GetPlayer1State()
{
return player1;
}
JoyState InputManager_GetPlayer2State()
{
return player2;
}
Byte InputManager_GetJoystickByte(int player)
{
if (player == 0)
return JoyStateToByte(player1);
if (player == 1)
return JoyStateToByte(player2);
return 0xFF;
}
bool InputManager_IsSDLKeyPressed(SDL_Keycode key)
{
const bool* keyboardState = SDL_GetKeyboardState(nullptr);
SDL_Scancode scan = SDL_GetScancodeFromKey(key, nullptr);
if (scan == SDL_SCANCODE_UNKNOWN)
return false;
return keyboardState[scan];
}