From dd83126b20122915ca673f0f385d089743f8bc4b Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Tue, 31 Dec 2024 10:22:43 +0300 Subject: More Muvement Improvements - You can now hold a direction to turn to in the next frame --- Week1-Pacman/src/pacman.c | 48 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'Week1-Pacman/src/pacman.c') diff --git a/Week1-Pacman/src/pacman.c b/Week1-Pacman/src/pacman.c index e91e773..5a46a6d 100644 --- a/Week1-Pacman/src/pacman.c +++ b/Week1-Pacman/src/pacman.c @@ -9,7 +9,7 @@ SDL_Rect* get_colliding_tile_raw(SDL_Rect*, struct map* map); SDL_Rect* get_colliding_tile(struct pacman* pacman, struct map* map); -void handle_pacman_input(SDL_Event* e, struct pacman* pacman, struct map* map) { +void handle_pacman_input(const char* keyboard, struct pacman* pacman, struct map* map) { SDL_Rect r = { .x = pacman->xpos, .y = pacman->ypos, @@ -17,32 +17,26 @@ void handle_pacman_input(SDL_Event* e, struct pacman* pacman, struct map* map) { .h = PACMAN_SIDE }; - if(e->type == SDL_KEYDOWN) { - switch(e->key.keysym.sym) { - case SDLK_UP: - r.y--; - if(get_colliding_tile_raw(&r, map) == NULL) - pacman->facing = FACING_UP; - break; - case SDLK_DOWN: - r.y++; - - if(get_colliding_tile_raw(&r, map) == NULL) - pacman->facing = FACING_DOWN; - break; - case SDLK_LEFT: - r.x--; - - if(get_colliding_tile_raw(&r, map) == NULL) - pacman->facing = FACING_LEFT; - break; - case SDLK_RIGHT: - r.x++; - - if(get_colliding_tile_raw(&r, map) == NULL) - pacman->facing = FACING_RIGHT; - break; - } + if(keyboard[SDL_SCANCODE_UP]) { + r.y--; + + if(get_colliding_tile_raw(&r, map) == NULL) + pacman->facing = FACING_UP; + } else if(keyboard[SDL_SCANCODE_DOWN]) { + r.y++; + + if(get_colliding_tile_raw(&r, map) == NULL) + pacman->facing = FACING_DOWN; + } else if(keyboard[SDL_SCANCODE_LEFT]) { + r.x--; + + if(get_colliding_tile_raw(&r, map) == NULL) + pacman->facing = FACING_LEFT; + } else if(keyboard[SDL_SCANCODE_RIGHT]) { + r.x++; + + if(get_colliding_tile_raw(&r, map) == NULL) + pacman->facing = FACING_RIGHT; } } -- cgit v1.2.3