-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource.c
More file actions
73 lines (57 loc) · 1.84 KB
/
resource.c
File metadata and controls
73 lines (57 loc) · 1.84 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "resource.h"
#define MAX_TEXTURES 17
ResourceManager resourceManager;
const char* textureResources[] = {
"resources/JamonAndar0.png",
"resources/JamonAndar1.png",
"resources/JamonAndar2.png",
"resources/JamonAndar3.png",
"resources/JamonAgachada0.png",
"resources/JamonAgachada1.png",
"resources/JamonAgachada2.png",
"resources/JamonAgachada3.png",
"resources/pino1.png",
"resources/cactus1.png",
"resources/cactus2.png",
"resources/petrodactil0.png",
"resources/petrodactil1.png",
"resources/bg.png",
"resources/far.png",
"resources/mountains.png",
"resources/mountain-trees.png"
};
SoundResource soundResources[] = {
};
void ResourceManagerInit() {
char buffer[256];
resourceManager.textureCount = MAX_TEXTURES;
resourceManager.textures = (TextureResource*)malloc(sizeof(TextureResource) * resourceManager.textureCount);
for (int i = 0; i < resourceManager.textureCount; i++) {
sprintf(buffer, "%s/%s", GetWorkingDirectory(), textureResources[i]);
resourceManager.textures[i].Texture = LoadTexture(buffer);
}
resourceManager.soundCount = 0;
resourceManager.sounds = NULL;
}
Texture2D* ResourceGetTexture(int index) {
if (index < 0 || index >= resourceManager.textureCount) {
return NULL;
}
return &resourceManager.textures[index].Texture;
}
Sound* ResourceGetSound(int index) {
if (index < 0 || index >= resourceManager.soundCount) {
return NULL;
}
return &resourceManager.sounds[index].Sound;
}
void ResourceManagerUnload() {
for (int i = 0; i < resourceManager.textureCount; i++) {
UnloadTexture(resourceManager.textures[i].Texture);
}
free(resourceManager.textures);
free(resourceManager.sounds);
}