From e05dbe42fd8ffc6601887d19afcba545a6401733 Mon Sep 17 00:00:00 2001 From: nathansmith117 Date: Thu, 15 Feb 2024 16:10:43 -0700 Subject: Untested asset loader thingy --- src/assets.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/assets.h | 15 +++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) (limited to 'src') 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 + +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 -- cgit v1.2.3