big asset rework
This commit is contained in:
@@ -8,4 +8,18 @@ typedef struct {
|
||||
float rotation;
|
||||
} TextureAsset;
|
||||
|
||||
typedef struct {
|
||||
const char* path;
|
||||
} ShaderAsset;
|
||||
|
||||
typedef struct {
|
||||
const char* path;
|
||||
} SoundtrackAsset;
|
||||
|
||||
typedef struct {
|
||||
const TextureAsset *textureAssets;
|
||||
const ShaderAsset *shaderAssets;
|
||||
const SoundtrackAsset *soundtrackAssets;
|
||||
} Assets;
|
||||
|
||||
#endif // ASSET_H
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifndef MUSICMANAGER_H
|
||||
#define MUSICMANAGER_H
|
||||
|
||||
typedef struct {
|
||||
Music music;
|
||||
bool playing;
|
||||
} MyMusic;
|
||||
|
||||
MyMusic CreateMusic(char* musicPath){
|
||||
MyMusic music = {
|
||||
.music = LoadMusicStream(musicPath),
|
||||
.playing = 0
|
||||
};
|
||||
PlayMusicStream(music.music);
|
||||
return music;
|
||||
}
|
||||
|
||||
void UpdateMusic(MyMusic* music){
|
||||
UpdateMusicStream(music->music);
|
||||
}
|
||||
|
||||
#endif // MUSICMANAGER_H
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ typedef struct {
|
||||
float strength;
|
||||
} PostProcessing;
|
||||
|
||||
PostProcessing CreatePostFX(const char* shaderPath, float strength){
|
||||
PostProcessing CreatePostFX(const char* shaderPath){
|
||||
PostProcessing postFX = {0};
|
||||
postFX.shader = LoadShader(NULL, shaderPath);
|
||||
|
||||
@@ -17,7 +17,7 @@ PostProcessing CreatePostFX(const char* shaderPath, float strength){
|
||||
return postFX;
|
||||
}
|
||||
|
||||
postFX.strength = strength;
|
||||
postFX.strength = 0.3f;
|
||||
postFX.resolutionLoc = GetShaderLocation(postFX.shader, "resolution");
|
||||
postFX.strengthLoc = GetShaderLocation(postFX.shader, "strength");
|
||||
Vector2 resolution = { (float)GetScreenWidth(), (float)GetScreenHeight() };
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef SOUNDTRACK_H
|
||||
#define SOUNDTRACK_H
|
||||
|
||||
typedef struct {
|
||||
Music music;
|
||||
bool playing;
|
||||
} Soundtrack;
|
||||
|
||||
Soundtrack LoadSoundtrack(const char* musicPath){
|
||||
Soundtrack soundtrack = {
|
||||
.music = LoadMusicStream(musicPath),
|
||||
.playing = 0
|
||||
};
|
||||
PlayMusicStream(soundtrack.music);
|
||||
return soundtrack;
|
||||
}
|
||||
|
||||
void UpdateSoundtrack(Soundtrack *soundtrack){
|
||||
UpdateMusicStream(soundtrack->music);
|
||||
}
|
||||
|
||||
#endif // SOUNDTRACK_H
|
||||
|
||||
+48
-58
@@ -4,29 +4,21 @@
|
||||
#include "../engine/camera.h"
|
||||
#include "../engine/input.h"
|
||||
#include "../engine/postfx.h"
|
||||
#include "../engine/musicmanager.h"
|
||||
#include "../engine/soundtrack.h"
|
||||
#include "../engine/asset.h"
|
||||
#include "../engine/applicationstate.h"
|
||||
#include "gameassets.h"
|
||||
#include "floor.h"
|
||||
#include "player.h"
|
||||
#include "bee.h"
|
||||
#include "hive.h"
|
||||
#include "flowers.h"
|
||||
|
||||
typedef enum {
|
||||
PLAYER,
|
||||
FLOWER,
|
||||
BEE,
|
||||
GRASS,
|
||||
HIVE,
|
||||
TEX_COUNT
|
||||
} TextureID;
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
PostProcessing postFX;
|
||||
MyMusic ambient;
|
||||
Assets assets;
|
||||
Texture2D textures[TEX_COUNT];
|
||||
PostProcessing postFX[SHADER_COUNT];
|
||||
Soundtrack soundtracks[SOUNDTRACK_COUNT];
|
||||
RenderTexture2D target;
|
||||
Floor floor;
|
||||
Object hive;
|
||||
@@ -36,60 +28,59 @@ typedef struct {
|
||||
Camera2D camera;
|
||||
Mouse mouse;
|
||||
Image image;
|
||||
TextureAsset textureAssets[TEX_COUNT];
|
||||
Texture2D textures[TEX_COUNT];
|
||||
} GameState;
|
||||
|
||||
void InitGame(GameState* g, Display *display){
|
||||
void InitGame(GameState* g, Display *display){
|
||||
|
||||
InitAudioDevice();
|
||||
g->assets = (Assets){
|
||||
.textureAssets = texAssets,
|
||||
.shaderAssets = shaderAssets,
|
||||
.soundtrackAssets = soundtrackAssets
|
||||
};
|
||||
|
||||
for (int i = 0; i < TEX_COUNT; i++){
|
||||
g->textures[i] = LoadTexture(g->assets.textureAssets[i].path);
|
||||
}
|
||||
|
||||
for (int i = 0; i < SHADER_COUNT; i++){
|
||||
g->postFX[i] = CreatePostFX(g->assets.shaderAssets[i].path);
|
||||
}
|
||||
|
||||
for (int i = 0; i < SOUNDTRACK_COUNT; i++){
|
||||
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
|
||||
}
|
||||
|
||||
// Target texture
|
||||
g->target = LoadRenderTexture(display->width, display->height);
|
||||
|
||||
// Static Entities
|
||||
g->flowers = CreateFlowers(g->textures[FLOWER], g->assets.textureAssets[FLOWER].frameWidth, g->assets.textureAssets[FLOWER].rotation, 50.0f);
|
||||
g->floor = CreateFloor(g->textures[GRASS], g->assets.textureAssets[GRASS].frameWidth);
|
||||
g->hive = CreateHive(g->textures[HIVE], g->assets.textureAssets[HIVE].frameWidth);
|
||||
|
||||
g->postFX = CreatePostFX("shaders/postfx.fs", 0.3f);
|
||||
// Animated Entities
|
||||
g->player = CreatePlayer(IDLE_DOWN, HOE, g->textures[PLAYER], g->assets.textureAssets[PLAYER].frameWidth, 4, 2, g->hive.position, g->assets.textureAssets[PLAYER].rotation, 50.0f);
|
||||
g->bee1 = CreateBee(FLYING, g->textures[BEE], g->assets.textureAssets[BEE].frameWidth, 4, 10, g->hive.position, 10.0f, &g->flowers, &g->hive);
|
||||
|
||||
g->ambient = CreateMusic("assets/beez.mp3");
|
||||
|
||||
g->textureAssets[PLAYER] = (TextureAsset){"assets/character/character.png", 64.0f, 64.0f, 180.0f};
|
||||
g->textureAssets[FLOWER] = (TextureAsset){"assets/flower.png", 16.0f, 16.0f, 45.0f};
|
||||
g->textureAssets[BEE] = (TextureAsset){"assets/character_bee.png", 16.0f, 16.0f, 0.0f};
|
||||
g->textureAssets[GRASS] = (TextureAsset){"assets/grass.png", 16.0f, 16.0f, 0.0f};
|
||||
g->textureAssets[HIVE] = (TextureAsset){"assets/hive.png", 32.0f, 32.0f, 0.0f};
|
||||
|
||||
g->textures[PLAYER] = LoadTexture(g->textureAssets[PLAYER].path);
|
||||
g->textures[FLOWER] = LoadTexture(g->textureAssets[FLOWER].path);
|
||||
g->textures[BEE] = LoadTexture(g->textureAssets[BEE].path);
|
||||
g->textures[GRASS] = LoadTexture(g->textureAssets[GRASS].path);
|
||||
g->textures[HIVE] = LoadTexture(g->textureAssets[HIVE].path);
|
||||
|
||||
g->player = CreatePlayer(IDLE_DOWN, g->textures[PLAYER], g->textureAssets[PLAYER].frameWidth, 4, 5, g->hive.position, g->textureAssets[PLAYER].rotation, 50.0f);
|
||||
g->flowers = CreateFlowers(g->textures[FLOWER], g->textureAssets[FLOWER].frameWidth, g->textureAssets[FLOWER].rotation, 50.0f);
|
||||
g->floor = CreateFloor(g->textures[GRASS], g->textureAssets[GRASS].frameWidth);
|
||||
g->hive = CreateHive(g->textures[HIVE], g->textureAssets[HIVE].frameWidth);
|
||||
g->bee1 = CreateBee(g->textures[BEE], g->textureAssets[BEE].frameWidth, 4, 10, g->hive.position, 10.0f, &g->flowers, &g->hive);
|
||||
|
||||
// I/O
|
||||
g->camera = CreateCamera(display->width, display->height, g->player.physics.position, 5.0f);
|
||||
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f);
|
||||
|
||||
g->target = LoadRenderTexture(display->width, display->height);
|
||||
}
|
||||
|
||||
void UpdateGame(GameState* g, State *state){
|
||||
SetTargetFPS(0);
|
||||
UpdatePostFX(&g->postFX);
|
||||
UpdateMusic(&g->ambient);
|
||||
if (GetFPS() <= 60){ SetTargetFPS(0); }
|
||||
if (IsKeyPressed(KEY_ESCAPE)){ state->currentScreen = MENU; }
|
||||
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE)) { state->running = false; }
|
||||
for (int i = 0; i < SHADER_COUNT; i++){ UpdatePostFX(&g->postFX[i]); }
|
||||
for (int i = 0; i < SOUNDTRACK_COUNT; i++){ UpdateSoundtrack(&g->soundtracks[i]); }
|
||||
|
||||
UpdateMouse(&g->mouse, &g->camera);
|
||||
UpdateCamera2D(&g->camera, &g->player.physics.position, &g->mouse);
|
||||
UpdateFloor(&g->floor, &g->camera);
|
||||
UpdatePlayer(&g->player);
|
||||
UpdateBee(&g->bee1, &g->flowers, &g->hive);
|
||||
|
||||
if (IsKeyPressed(KEY_ESCAPE)){
|
||||
state->currentScreen = MENU;
|
||||
}
|
||||
|
||||
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE)) {
|
||||
state->running = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RenderComponents(GameState* g){
|
||||
@@ -109,20 +100,19 @@ void RenderGame(GameState* g){
|
||||
EndTextureMode();
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
RenderPostFX(&g->postFX, &g->target);
|
||||
for (int i = 0; i < SHADER_COUNT; i++){
|
||||
RenderPostFX(&g->postFX[i], &g->target);
|
||||
}
|
||||
DrawFPS(10, 10);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
void CleanupGame(GameState* g){
|
||||
UnloadPostFX(&g->postFX);
|
||||
for (int i = 0; i < SHADER_COUNT; i++){ UnloadPostFX(&g->postFX[i]); }
|
||||
for (int i = 0; i < TEX_COUNT; i++){ if (g->textures[i].id > 0) { UnloadTexture(g->textures[i]); } }
|
||||
for (int i = 0; i < SOUNDTRACK_COUNT; i++){ UnloadMusicStream(g->soundtracks[i].music); }
|
||||
UnloadRenderTexture(g->target);
|
||||
for (int i = 0; i < TEX_COUNT; i++){
|
||||
if (g->textures[i].id > 0) { UnloadTexture(g->textures[i]); }
|
||||
}
|
||||
UnloadMusicStream(g->ambient.music);
|
||||
free(g->flowers.data);
|
||||
CloseAudioDevice();
|
||||
}
|
||||
|
||||
#endif // GAME_H
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef GAMEASSETS_H
|
||||
#define GAMEASSETS_H
|
||||
#include "../engine/asset.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef enum {
|
||||
PLAYER,
|
||||
PLAYER_ACTIONS,
|
||||
TOOLS,
|
||||
FLOWER,
|
||||
BEE,
|
||||
GRASS,
|
||||
HIVE,
|
||||
TEX_COUNT
|
||||
} TextureID;
|
||||
|
||||
const TextureAsset texAssets[TEX_COUNT] = {
|
||||
{"assets/SproutLandsBasic/Characters/character.png", 48.0f, 48.0f, 180.0f},
|
||||
{"assets/SproutLandsBasic/Characters/BasicCharakterActions.png", 48.0f, 48.0f, 180.0f},
|
||||
{"assets/SproutLandsBasic/Objects/tools.png", 48.0f, 16.0f, 180.0f},
|
||||
{"assets/flower.png", 16.0f, 16.0f, 45.0f},
|
||||
{"assets/character_bee.png", 16.0f, 16.0f, 0.0f},
|
||||
{"assets/grass.png", 16.0f, 16.0f, 0.0f},
|
||||
{"assets/hive.png", 32.0f, 32.0f, 0.0f}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef enum {
|
||||
POST_FX,
|
||||
SHADER_COUNT
|
||||
} ShaderID;
|
||||
|
||||
|
||||
const ShaderAsset shaderAssets[SHADER_COUNT] = {
|
||||
{"shaders/postfx.fs"}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef enum {
|
||||
BEE_AMBIENT,
|
||||
SOUNDTRACK_COUNT
|
||||
} SoundtrackID;
|
||||
|
||||
const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = {
|
||||
{"assets/beez.mp3"}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // GAMEASSETS_H
|
||||
Reference in New Issue
Block a user