-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputHandler.cpp
61 lines (55 loc) · 1.16 KB
/
InputHandler.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
#include "InputHandler.h"
InputHandler::InputHandler() {
}
InputHandler::~InputHandler() {
}
Event InputHandler::handleKeyStates() {
if (currentKeyStates[SDL_SCANCODE_UP]) {
return MOVE_UP;
}
else if (currentKeyStates[SDL_SCANCODE_DOWN]) {
return MOVE_DOWN;
}
else if (currentKeyStates[SDL_SCANCODE_LEFT]) {
return MOVE_LEFT;
}
else if (currentKeyStates[SDL_SCANCODE_RIGHT]) {
return MOVE_RIGHT;
}
else if (currentKeyStates[SDL_SCANCODE_ESCAPE]) {
return QUIT;
}
else if (currentKeyStates[SDL_SCANCODE_N]) {
return NEW_GAME;
}
else return handleNextMap();
}
Event InputHandler::handleNextMap() {
// poll event because it reads key just when its pressed
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_p) {
return NEXT_MAP;
}
break;
default:
return NO_EVENT;
}
}
return NO_EVENT;
}
Event InputHandler::handleQuit() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
return QUIT;
break;
default:
return NO_EVENT;
}
}
return NO_EVENT;
}