-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.c
69 lines (47 loc) · 1.11 KB
/
input.c
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"
#include <SDL/SDL.h>
static bool keyState[SDLK_LAST + 1];
static bool quit;
static int keyMap[KEY_COUNT] = {SDLK_LEFT, SDLK_RIGHT, SDLK_UP, SDLK_DOWN, SDLK_SPACE, SDLK_ESCAPE};
static int directionKeyMap[DIR_COUNT] = {KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN};
void input_Init()
{
int i;
for(i = 0; i <= SDLK_LAST; ++i)
keyState[i] = false;
quit = false;
}
bool input_IsDirPressed(Direction dir)
{
return keyState[keyMap[directionKeyMap[dir]]];
}
bool input_IsKeyPressed(Key key)
{
return keyState[keyMap[key]];
}
void input_UnsetPressed(Key key)
{
keyState[keyMap[key]] = false;
}
bool input_WantQuit()
{
return quit;
}
void input_PumpEvents()
{
SDL_PumpEvents();
SDL_Event event;
quit = false;
while(SDL_PollEvent(&event))
{
if((event.type == SDL_KEYDOWN) || (event.type == SDL_KEYUP))
{
bool val;
if(event.type == SDL_KEYDOWN) val = true;
else val = false;
keyState[event.key.keysym.sym] = val;
}
if(event.type == SDL_QUIT)
quit = true;
}
}