From 3422a87bdb087b6d927203e266beb71027779dbe Mon Sep 17 00:00:00 2001 From: "Dobbertin, Niclas" Date: Sat, 24 Jun 2023 23:04:23 +0200 Subject: init code --- input.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 input.c (limited to 'input.c') 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 + +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]); */ +/* } */ -- cgit v1.2.3