diff options
Diffstat (limited to 'Week1-Pacman/src/pacman.c')
-rw-r--r-- | Week1-Pacman/src/pacman.c | 44 |
1 files changed, 44 insertions, 0 deletions
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 <SDL2/SDL.h> +#include <stdbool.h> +#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) { + +} |