diff options
| author | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 23:02:32 +0100 |
|---|---|---|
| committer | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 23:02:32 +0100 |
| commit | 6b8af9cf83851c075c6c9514b1deaa931c2b19a4 (patch) | |
| tree | 428986b49c32e21d3f7a3c2dfa41858ae0153209 /09-september/ProcessInput.c | |
Initial commit
Diffstat (limited to '09-september/ProcessInput.c')
| -rw-r--r-- | 09-september/ProcessInput.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/09-september/ProcessInput.c b/09-september/ProcessInput.c new file mode 100644 index 0000000..0f088f8 --- /dev/null +++ b/09-september/ProcessInput.c @@ -0,0 +1,47 @@ +#include "game.h" +#include <string.h> + +void ProcessInput(Game *game) +{ + static Vec2 mousePosition; + SDL_Event e; + + while(SDL_PollEvent(&e)) + { + switch(e.type) + { + case SDL_QUIT: + game->gameState = EXIT; + break; + + case SDL_MOUSEMOTION: + mousePosition.x = (GLfloat) e.motion.x; + mousePosition.y = (GLfloat) e.motion.y; + camera_mouse_update(game->camera, &mousePosition); + break; + + case SDL_KEYDOWN: + Input_PressKey(e.key.keysym.scancode); + break; + + case SDL_KEYUP: + Input_ReleaseKey(e.key.keysym.scancode); + break; + } + + if(Input_isKeyPressed(SDL_SCANCODE_UP)) + camera_move_foward(game->camera); + + if(Input_isKeyPressed(SDL_SCANCODE_DOWN)) + camera_move_backward(game->camera); + + if(Input_isKeyPressed(SDL_SCANCODE_LEFT)) + camera_move_left(game->camera); + + if(Input_isKeyPressed(SDL_SCANCODE_RIGHT)) + camera_move_right(game->camera); + + if(Input_isKeyPressed(SDL_SCANCODE_ESCAPE)) + game->gameState = EXIT; + } +} |
