From ebc3c130ed4d8ee6c44fc902bc4ee955799d1ac5 Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Fri, 13 Dec 2024 16:22:39 +0300 Subject: Initial Commit --- Week1-Pacman/src/pacman.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Week1-Pacman/src/pacman.c (limited to 'Week1-Pacman/src/pacman.c') diff --git a/Week1-Pacman/src/pacman.c b/Week1-Pacman/src/pacman.c new file mode 100644 index 0000000..6eef8f4 --- /dev/null +++ b/Week1-Pacman/src/pacman.c @@ -0,0 +1,44 @@ +#include +#include +#include "pacman.h" + +#define PACMAN_SPEED 40 + +void handle_pacman_input(SDL_Event* e, struct pacman* pacman) { + + if(e->type == SDL_KEYDOWN) { + switch(e->key.keysym.sym) { + case SDLK_UP: + pacman->facing = FACING_UP; + break; + case SDLK_DOWN: + pacman->facing = FACING_DOWN; + break; + case SDLK_LEFT: + pacman->facing = FACING_LEFT; + break; + case SDLK_RIGHT: + pacman->facing = FACING_RIGHT; + break; + } + } + +} + +void update_pacman(struct pacman* pacman, float dt) { + + if(pacman->facing == FACING_UP) { + pacman->ypos -= PACMAN_SPEED * dt; + } else if(pacman->facing == FACING_DOWN) { + pacman->ypos += PACMAN_SPEED * dt; + } else if(pacman->facing == FACING_LEFT) { + pacman->xpos -= PACMAN_SPEED * dt; + } else { + pacman->xpos += PACMAN_SPEED * dt; + } + +} + +void draw_pacman(SDL_Renderer* ren, const struct pacman* pacman) { + +} -- cgit v1.2.3