aboutsummaryrefslogtreecommitdiff
path: root/progress/src/procesar.c
diff options
context:
space:
mode:
authorThomas Guillermo Albers Raviola <thomas@thomaslabs.org>2026-01-16 19:38:33 +0100
committerThomas Guillermo Albers Raviola <thomas@thomaslabs.org>2026-01-16 19:38:33 +0100
commita90db3b7b6e87e24c789b5db222f1cef92809bde (patch)
tree2096abcb1ac1ea970a51e598257186bc4e030b22 /progress/src/procesar.c
Initial commit
Diffstat (limited to 'progress/src/procesar.c')
-rw-r--r--progress/src/procesar.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/progress/src/procesar.c b/progress/src/procesar.c
new file mode 100644
index 0000000..aa7f104
--- /dev/null
+++ b/progress/src/procesar.c
@@ -0,0 +1,127 @@
+#include "main.h"
+
+int processEvents(SDL_Window *window,GameState *gameState)
+{
+ SDL_Event event;
+ int done = 0;
+
+ while(SDL_PollEvent(&event))
+ {
+ switch(event.type)
+ {
+ case SDL_WINDOWEVENT_CLOSE:
+ {
+ if(window)
+ {
+ SDL_DestroyWindow(window);
+ window = NULL;
+ done = 1;
+ }
+ }
+ break;
+ case SDL_KEYDOWN:
+ {
+ switch(event.key.keysym.sym)
+ {
+ case SDLK_ESCAPE:
+ done = 1;
+ break;
+
+ case SDLK_e:
+ {
+ if(!gameState->player2.facing_left)
+ {
+ gameState->player2.shooting = addBullet(gameState->player2.x+35, gameState->player2.y+20, 7, gameState, 2);
+ }
+ else
+ {
+ gameState->player2.shooting = addBullet(gameState->player2.x+5, gameState->player2.y+20, -7, gameState, 2);
+ }
+ if(gameState->player2.shooting)
+ Mix_PlayChannel(-1, gameState->disparo, 0);
+ }
+ break;
+ }
+ }
+ break;
+ case SDL_QUIT:
+ //quit out of the game
+ done = 1;
+ break;
+
+ case SDL_MOUSEBUTTONDOWN:
+ {
+ if(!gameState->player1.facing_left)
+ {
+ gameState->player1.shooting = addBullet(gameState->player1.x+35, gameState->player1.y+20, 7, gameState, 1);
+ }
+ else
+ {
+ gameState->player1.shooting = addBullet(gameState->player1.x+5, gameState->player1.y+20, -7, gameState, 1);
+ }
+ if(gameState->player1.shooting)
+ Mix_PlayChannel(-1, gameState->disparo, 0);
+ }
+ break;
+ }
+ }
+
+ const Uint8 *state = SDL_GetKeyboardState(NULL);
+ if(state[SDL_SCANCODE_LEFT])
+ {
+ gameState->player1.x -= 5;
+ gameState->player1.facing_left = 1;
+ gameState->player1.walking = 1;
+ }
+ if(state[SDL_SCANCODE_RIGHT])
+ {
+ gameState->player1.x += 5;
+ gameState->player1.facing_left = 0;
+ gameState->player1.walking = 1;
+ }
+ if(state[SDL_SCANCODE_UP])
+ {
+ if(gameState->player1.salto == 1 && gameState->player1.dy != 0)
+ {
+
+ }
+ else if(gameState->player1.salto == 0 && gameState->player1.dy == 0)
+ {
+ gameState->player1.dy = -15;
+ gameState->player1.salto = 1;
+ }
+ }
+ if(state[SDL_SCANCODE_A])
+ {
+ gameState->player2.x -= 5;
+ gameState->player2.facing_left = 1;
+ gameState->player2.walking = 1;
+ }
+ if(state[SDL_SCANCODE_D])
+ {
+ gameState->player2.x += 5;
+ gameState->player2.facing_left = 0;
+ gameState->player2.walking = 1;
+ }
+ if(state[SDL_SCANCODE_W])
+ {
+ if(gameState->player2.salto == 1 && gameState->player2.dy != 0)
+ {
+
+ }
+ else if(gameState->player2.salto == 0 && gameState->player2.dy == 0)
+ {
+ gameState->player2.dy = -15;
+ gameState->player2.salto = 1;
+ }
+ }
+ if(state[SDL_SCANCODE_SPACE])
+ {
+ gameState->player2.y -= 5;
+ }
+ if(state[SDL_SCANCODE_S])
+ {
+ gameState->player2.y += 5;
+ }
+ return done;
+}