summaryrefslogtreecommitdiff
path: root/Week1-Pacman/src/resources.c
diff options
context:
space:
mode:
Diffstat (limited to 'Week1-Pacman/src/resources.c')
-rw-r--r--Week1-Pacman/src/resources.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/Week1-Pacman/src/resources.c b/Week1-Pacman/src/resources.c
new file mode 100644
index 0000000..71f02aa
--- /dev/null
+++ b/Week1-Pacman/src/resources.c
@@ -0,0 +1,30 @@
+#include <SDL2/SDL_image.h>
+#include "resources.h"
+
+SDL_Texture* character_spritesheet;
+SDL_Texture* map_texture;
+
+SDL_Texture* load_texture(struct demo* demo, const char* image_name) {
+ SDL_Texture* texture =
+ IMG_LoadTexture(demo->ren, image_name);
+
+ if(texture == NULL) {
+ printf("Failed to load textue %s, error: %s, exitting!",
+ image_name, IMG_GetError());
+ exit(1);
+ }
+
+ return texture;
+}
+
+void load_resources(struct demo* demo) {
+ if(!character_spritesheet) {
+ character_spritesheet =
+ load_texture(demo, "assets/Sprites/sprites.png");
+ }
+
+ if(!map_texture) {
+ map_texture =
+ load_texture(demo, "assets/Sprites/Tileset.png");
+ }
+}