summaryrefslogtreecommitdiff
path: root/Week1-Pacman/src/animation.c
diff options
context:
space:
mode:
Diffstat (limited to 'Week1-Pacman/src/animation.c')
-rw-r--r--Week1-Pacman/src/animation.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Week1-Pacman/src/animation.c b/Week1-Pacman/src/animation.c
index 40be24a..88fce7b 100644
--- a/Week1-Pacman/src/animation.c
+++ b/Week1-Pacman/src/animation.c
@@ -1,8 +1,12 @@
-#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "animation.h"
+#include <SDL2/SDL_image.h>
+
+SDL_Rect* current_frame(struct animation* animation) {
+ return &animation->frames[animation->current_frame];
+}
void init_animation(struct animation* animation,
struct animation_init* init) {
@@ -13,6 +17,13 @@ void init_animation(struct animation* animation,
exit(1);
}
+ animation->texture = IMG_LoadTexture(init->ren, init->spritesheet);
+
+ if(animation->texture == NULL) {
+ printf("Failed to load spritesheet %s, error: %s, exitting!\n",
+ init->spritesheet, IMG_GetError());
+ }
+
animation->num_frames = initial_frame_count;
int size = initial_frame_count * sizeof(float);
@@ -39,3 +50,11 @@ void update_animation(struct animation* animation, float dt) {
(frame_index + 1) % animation->num_frames;
}
}
+
+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);
+}