-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputManager.cpp
More file actions
122 lines (108 loc) · 2.12 KB
/
InputManager.cpp
File metadata and controls
122 lines (108 loc) · 2.12 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "InputManager.h"
#include "Game.h"
InputManager::InputManager()
{
leftWasDown = false;
rightWasDown = false;
}
InputManager::~InputManager()
{
}
void InputManager::update()
{
Uint8* keystate = SDL_GetKeyState(NULL);
SDL_Event event;
// Reset Player toMove
Game::getInstance()->getPlayer()->setMove(0);
// Keys held
if (keystate[SDLK_LEFT])
{
gpEventSystem->fireEvent(LEFT_HELD);
leftWasDown = true;
}
else
{
if (leftWasDown)
{
gpEventSystem->fireEvent(LEFT_RELEASED);
}
leftWasDown = false;
}
if (keystate[SDLK_RIGHT])
{
gpEventSystem->fireEvent(RIGHT_HELD);
rightWasDown = true;
}
else
{
if (rightWasDown)
{
gpEventSystem->fireEvent(RIGHT_RELEASED);
}
rightWasDown = false;
}
if (keystate[SDLK_UP])
{
gpEventSystem->fireEvent(UP_HELD);
}
if (keystate[SDLK_DOWN])
{
gpEventSystem->fireEvent(DOWN_HELD);
}
if (keystate[SDLK_SPACE])
{
gpEventSystem->fireEvent(SPACE_HELD);
}
// Keys pressed
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
Game::getInstance()->setState(QUIT);
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_F1:
Game::getInstance()->getSaveSystem()->saveGame();
break;
case SDLK_F2:
Game::getInstance()->getSaveSystem()->loadGame();
break;
case SDLK_LEFT:
gpEventSystem->fireEvent(LEFT_PRESSED);
break;
case SDLK_RIGHT:
gpEventSystem->fireEvent(RIGHT_PRESSED);
break;
case SDLK_UP:
gpEventSystem->fireEvent(UP_PRESSED);
break;
case SDLK_DOWN:
gpEventSystem->fireEvent(DOWN_PRESSED);
break;
case SDLK_ESCAPE:
gpEventSystem->fireEvent(ESCAPE_PRESSED);
break;
case SDLK_RETURN:
gpEventSystem->fireEvent(ENTER_PRESSED);
break;
case SDLK_b:
gpEventSystem->fireEvent(B_PRESSED);
break;
case SDLK_1:
gpEventSystem->fireEvent(NUM_1_PRESSED);
break;
case SDLK_2:
gpEventSystem->fireEvent(NUM_2_PRESSED);
break;
case SDLK_3:
gpEventSystem->fireEvent(NUM_3_PRESSED);
break;
case SDLK_4:
gpEventSystem->fireEvent(NUM_4_PRESSED);
break;
}
}
}
}