diff options
author | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-02-15 23:10:43 +0000 |
---|---|---|
committer | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-02-15 23:10:43 +0000 |
commit | e05dbe42fd8ffc6601887d19afcba545a6401733 (patch) | |
tree | eb170350052057385e82d9b273f041dae809f18c | |
parent | 9211212e939561c92e9a29baf0b61408d0b58c7a (diff) | |
download | PenguinYippies-e05dbe42fd8ffc6601887d19afcba545a6401733.tar.gz PenguinYippies-e05dbe42fd8ffc6601887d19afcba545a6401733.tar.bz2 PenguinYippies-e05dbe42fd8ffc6601887d19afcba545a6401733.zip |
Untested asset loader thingy
-rw-r--r-- | src/assets.c | 68 | ||||
-rw-r--r-- | src/assets.h | 15 |
2 files changed, 82 insertions, 1 deletions
diff --git a/src/assets.c b/src/assets.c index 4ed3d53..05e2b04 100644 --- a/src/assets.c +++ b/src/assets.c @@ -1 +1,69 @@ #include "assets.h" +#include <raylib.h> + +const char textureAssetsNames[TEXTURE_ASSET_COUNT][ASSETS_NAME_MAX] = { + "mainScreenBackground.png", + "penguinBackground.png", + "toEmperorsEmporiumIcon.png", + "toGameIcon.png" +}; + +const char animationAssetsNames[ANIMATION_ASSET_COUNT][ASSETS_NAME_MAX] = { + "buttonBox.gif", + "penguinLol.gif" +}; + +void loadTextures(Assets* assets) +{ + for (int i = 0; i < TEXTURE_ASSET_COUNT; ++i) + { + char filePath[ASSETS_NAME_MAX]; + snprintf(filePath, ASSETS_NAME_MAX, "assets/%s", textureAssetsNames[i]); + assets->textures[i] = LoadTexture(filePath); + } +} + +void loadAnimations(Assets* assets) +{ + for (int i = 0; i < ANIMATION_ASSET_COUNT; ++i) + { + char filePath[ASSETS_NAME_MAX]; + snprintf(filePath, ASSETS_NAME_MAX, "assets/%s", animationAssetsNames[i]); + assets->animations[i] = loadAnimationFromFile(filePath); + } +} + +// Used for setting different options in assets like animation delay. +void configureAssets(Assets* assets) +{ +} + +void initAssets(Assets* assets) +{ + TraceLog(LOG_INFO, "Loading assets"); + + loadTextures(assets); + loadAnimations(assets); + configureAssets(assets); + + TraceLog(LOG_INFO, "Assets loaded"); +} + +void closeAssets(Assets* assets) +{ + TraceLog(LOG_INFO, "Closing assets"); + + // Textures. + for (int i = 0; i < TEXTURE_ASSET_COUNT; ++i) + { + UnloadTexture(assets->textures[i]); + } + + // Animations. + for (int i = 0; i < ANIMATION_ASSET_COUNT; ++i) + { + freeAnimation(&assets->animations[i]); + } + + TraceLog(LOG_INFO, "Assets closed"); +} diff --git a/src/assets.h b/src/assets.h index 9846f3b..eed002b 100644 --- a/src/assets.h +++ b/src/assets.h @@ -1,10 +1,23 @@ #include "gameCommon.h" +#include "animation.h" #define ASSETS_NAME_MAX 100 -#define IMAGE_ASSET_COUNT 4 +#define TEXTURE_ASSET_COUNT 4 #define ANIMATION_ASSET_COUNT 2 #ifndef ASSETS_H #define ASSETS_H +// Stores the names of all the assets used. +extern const char textureAssetsNames[TEXTURE_ASSET_COUNT][ASSETS_NAME_MAX]; +extern const char animationAssetsNames[ANIMATION_ASSET_COUNT][ASSETS_NAME_MAX]; + +typedef struct Assets { + Texture textures[TEXTURE_ASSET_COUNT]; + Animation animations[ANIMATION_ASSET_COUNT]; +} Assets; + +void initAssets(Assets* assets); +void closeAssets(Assets* assets); + #endif |