summaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'input.c')
-rw-r--r--input.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/input.c b/input.c
new file mode 100644
index 0000000..5318279
--- /dev/null
+++ b/input.c
@@ -0,0 +1,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]); */
+/* } */