summaryrefslogtreecommitdiff
path: root/input.c
blob: 53182796dbbbc655770bd3f8678dadc456be6c5b (plain)
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 "input.h"

#include <stdio.h>

void handleKeyboardEvent(int *action_states, SDL_Event event)
{
	if (event.key.repeat != 0)
		return;
	switch (event.type) {
	case SDL_QUIT:
		action_states[ACTION_QUIT] = 1;
		break;
	case SDL_KEYDOWN:
		switch (event.key.keysym.sym) {
		case SDLK_q:
			action_states[ACTION_QUIT] = 1;
			break;
		case SDLK_w:
			action_states[ACTION_MOVE_UP] = 1;
			break;
		case SDLK_s:
			action_states[ACTION_MOVE_DOWN] = 1;
			break;
		case SDLK_a:
			action_states[ACTION_MOVE_LEFT] = 1;
			break;
		case SDLK_d:
			action_states[ACTION_MOVE_RIGHT] = 1;
			break;
		}
		break;
	case SDL_KEYUP:
		switch (event.key.keysym.sym) {
		case SDLK_w:
			action_states[ACTION_MOVE_UP] = 0;
			break;
		case SDLK_s:
			action_states[ACTION_MOVE_DOWN] = 0;
			break;
		case SDLK_a:
			action_states[ACTION_MOVE_LEFT] = 0;
			break;
		case SDLK_d:
			action_states[ACTION_MOVE_RIGHT] = 0;
			break;
		}
		break;
	}
}

/* int action_status(enum Actions action) */
/* { */
/* 	return actions_state[action]; */
/* } */

/* void action_toggle(enum Actions action) */
/* { */
/* 	printf("%d", actions_state[action]); */
/* 	actions_state[action] = 1; */
/* 	printf("%d", actions_state[action]); */
/* } */