diff options
author | banana <delgadillo.tyler@gmail.com> | 2024-03-22 13:46:36 -0700 |
---|---|---|
committer | banana <delgadillo.tyler@gmail.com> | 2024-03-22 13:46:36 -0700 |
commit | ad22993557296b02bc0c947cb3bb6247fac8f47f (patch) | |
tree | 2c83ab589acab8a5074583d625d54ec44677e5d0 /input.c |
Diffstat (limited to 'input.c')
-rw-r--r-- | input.c | 59 |
1 files changed, 59 insertions, 0 deletions
@@ -0,0 +1,59 @@ +#include <SDL2/SDL.h> +#include "./constants.h" +#include "./structs.h" + +extern App app; + +static void handle_key_down(SDL_KeyboardEvent *event) { + if(event->repeat == 0) { + if(event->keysym.sym == SDLK_ESCAPE) { + app.input |= INPUT_RESET; + } + if(event->keysym.sym == SDLK_a) { + app.input |= PADDLE_1_UP; + } + if(event->keysym.sym == SDLK_z) { + app.input |= PADDLE_1_DOWN; + } + if(event->keysym.sym == SDLK_QUOTE) { + app.input |= PADDLE_2_UP; + } + if(event->keysym.sym == SDLK_SLASH) { + app.input |= PADDLE_2_DOWN; + } + } +} + +static void handle_key_up(SDL_KeyboardEvent *event) { + if(event->repeat == 0) { + if(event->keysym.sym == SDLK_a) { + app.input ^= PADDLE_1_UP; + } + if(event->keysym.sym == SDLK_z) { + app.input ^= PADDLE_1_DOWN; + } + if(event->keysym.sym == SDLK_QUOTE) { + app.input ^= PADDLE_2_UP; + } + if(event->keysym.sym == SDLK_SLASH) { + app.input ^= PADDLE_2_DOWN; + } + } +} + +void process_input() { + SDL_Event event; + while(SDL_PollEvent(&event)) { + switch(event.type) { + case SDL_QUIT: + app.input |= INPUT_RESET; + break; + case SDL_KEYDOWN: + handle_key_down(&event.key); + break; + case SDL_KEYUP: + handle_key_up(&event.key); + break; + } + } +} |