summaryrefslogtreecommitdiff
path: root/Week1-Pacman/src/pacman.c
diff options
context:
space:
mode:
authorBoredGuy <osome3717@gmail.com>2024-12-14 12:08:02 +0300
committerBoredGuy <osome3717@gmail.com>2024-12-14 12:08:02 +0300
commitfc3032135f4da3662d6b727c70f22049d6e09231 (patch)
tree8e0caba74cc6749c76f211540fe908f6b9a3d476 /Week1-Pacman/src/pacman.c
parent993f45cec7a08a5b980ef5a08ea7ce19b877b743 (diff)
Update
- Finish animation system - Fix bug where leftward/upward movement was slightly faster than downward/forward movement
Diffstat (limited to 'Week1-Pacman/src/pacman.c')
-rw-r--r--Week1-Pacman/src/pacman.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/Week1-Pacman/src/pacman.c b/Week1-Pacman/src/pacman.c
index c0a9644..f3a4769 100644
--- a/Week1-Pacman/src/pacman.c
+++ b/Week1-Pacman/src/pacman.c
@@ -2,8 +2,8 @@
#include <stdbool.h>
#include "pacman.h"
-#define PACMAN_SPEED 40
-#define PACMAN_SIDE 20
+#define PACMAN_SPEED 261
+#define PACMAN_SIDE 40
void handle_pacman_input(SDL_Event* e, struct pacman* pacman) {
@@ -23,7 +23,6 @@ void handle_pacman_input(SDL_Event* e, struct pacman* pacman) {
break;
}
}
-
}
void update_pacman(struct pacman* pacman, float dt) {
@@ -38,8 +37,19 @@ void update_pacman(struct pacman* pacman, float dt) {
pacman->xpos += PACMAN_SPEED * dt;
}
+ update_animation(&pacman->animations[pacman->facing], dt);
}
-void draw_pacman(SDL_Renderer* ren, const struct pacman* pacman) {
+void draw_pacman(struct demo* demo, const struct pacman* pacman) {
+ const struct animation* current_animation =
+ &pacman->animations[pacman->facing];
+
+ SDL_Rect d_rect = {
+ .x = pacman->xpos,
+ .y = pacman->ypos,
+ .w = PACMAN_SIDE,
+ .h = PACMAN_SIDE
+ };
+ draw_animation(demo, current_animation, &d_rect);
}