summaryrefslogtreecommitdiff
path: root/Week1-Pacman/src/resources.c
blob: 71f02aa651126e5c9bbb91e65e860d0d0b3f2258 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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");
  }
}