diff options
author | BoredGuy <osome3717@gmail.com> | 2024-12-14 12:08:02 +0300 |
---|---|---|
committer | BoredGuy <osome3717@gmail.com> | 2024-12-14 12:08:02 +0300 |
commit | fc3032135f4da3662d6b727c70f22049d6e09231 (patch) | |
tree | 8e0caba74cc6749c76f211540fe908f6b9a3d476 /Week1-Pacman/src/animation.c | |
parent | 993f45cec7a08a5b980ef5a08ea7ce19b877b743 (diff) |
Update
- Finish animation system
- Fix bug where leftward/upward movement was slightly faster than
downward/forward movement
Diffstat (limited to 'Week1-Pacman/src/animation.c')
-rw-r--r-- | Week1-Pacman/src/animation.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Week1-Pacman/src/animation.c b/Week1-Pacman/src/animation.c index 88fce7b..0747ba1 100644 --- a/Week1-Pacman/src/animation.c +++ b/Week1-Pacman/src/animation.c @@ -4,7 +4,7 @@ #include "animation.h" #include <SDL2/SDL_image.h> -SDL_Rect* current_frame(struct animation* animation) { +const SDL_Rect* current_frame(const struct animation* animation) { return &animation->frames[animation->current_frame]; } @@ -22,6 +22,7 @@ void init_animation(struct animation* animation, if(animation->texture == NULL) { printf("Failed to load spritesheet %s, error: %s, exitting!\n", init->spritesheet, IMG_GetError()); + exit(1); } animation->num_frames = initial_frame_count; @@ -34,8 +35,9 @@ void init_animation(struct animation* animation, size = initial_frame_count * sizeof(SDL_Rect); animation->frames = malloc(size); - memcpy(animation->frames, init->initial_frame_times, size); + memcpy(animation->frames, init->initial_frames, size); + animation->angle = init->initial_angle; } void update_animation(struct animation* animation, float dt) { @@ -52,9 +54,13 @@ void update_animation(struct animation* animation, float dt) { } void draw_animation(struct demo* demo, - struct animation* animation, - SDL_Rect* d_rect) { - SDL_Rect* s_rect = current_frame(animation); - - demo_rendercopy(demo, animation->texture, s_rect, d_rect); + const struct animation* animation, + const SDL_Rect* d_rect) { + const SDL_Rect* s_rect = current_frame(animation); + + demo_rendercopy_ex(demo, animation->texture, + s_rect, d_rect, + animation->angle, + NULL, + SDL_FLIP_NONE); } |