This commit is contained in:
huaqo-games
2025-10-26 21:24:31 +01:00
parent f7b84f9016
commit 66b961d7ab
22 changed files with 406 additions and 165 deletions
+17 -37
View File
@@ -1,34 +1,26 @@
#ifndef GAME_H
#define GAME_H
#include <object.h>
#include <camera.h>
#include <input.h>
#include "floor.h"
#include "player.h"
#include "gameassets.h"
#include <postfx.h>
#include <soundtrack.h>
#include <asset.h>
#include <array.h>
#include <stdlib.h>
#include "gameassets.h"
#include "floor.h"
#include "player.h"
#include "bee.h"
#include "hive.h"
#include "flowers.h"
typedef struct
{
Assets assets;
Assets assets;
Texture2D textures[TEX_COUNT];
PostProcessing postFX[SHADER_COUNT];
Soundtrack soundtracks[SOUNDTRACK_COUNT];
RenderTexture2D target;
Floor floor;
Object hive;
Array* flowers;
Player player;
Bee bee1;
Camera2D camera;
Mouse mouse;
Image image;
@@ -57,22 +49,13 @@ void InitGame(GameState *g, Window *window)
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
}
// Target texture
g->target = LoadRenderTexture(window->width, window->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);
// 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);
// I/O
g->player = CreatePlayer();
g->floor = CreateFloor();
g->camera = CreateCamera(window->width, window->height, g->player.physics.position, 10.0f);
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &g->textures[CURSOR]);
Texture2D mouseTexture = LoadTexture("assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png");
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &mouseTexture);
}
void UpdateGame(GameState *g, State *state, Flags *flags)
@@ -85,15 +68,18 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
{
SetTargetFPS(0);
}
if (IsKeyPressed(KEY_ESCAPE))
{
state->currentView = MENU;
}
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))
{
state->running = false;
}
for (int i = 0; i < SHADER_COUNT; i++)
for (int i = 0; i < SHADER_COUNT; i++)
{
UpdatePostFX(&g->postFX[i]);
}
@@ -105,18 +91,13 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
UpdateMouse(&g->mouse, &g->camera);
UpdateCamera2D(&g->camera, &g->player.physics.position, &g->mouse);
UpdateFloor(&g->floor, &g->camera);
UpdatePlayer(&g->player, g->flowers);
UpdateArray(g->flowers, UpdateFlower);
// UpdateBee(&g->bee1, &g->flowers, &g->hive);
UpdatePlayer(&g->player);
}
void RenderComponents(GameState *g)
{
RenderFloor(&g->floor);
RenderSprite(&g->hive.sprite);
RenderArray(g->flowers, RenderFlower);
RenderSprite(&g->player.sprite);
RenderSprite(&g->bee1.sprite);
RenderPlayer(&g->player);
}
void RenderGame(GameState *g, const State *appState, Flags *flags)
@@ -128,13 +109,13 @@ void RenderGame(GameState *g, const State *appState, Flags *flags)
EndMode2D();
DrawTextureRec(g->mouse.cursorTexture, (Rectangle){0, 0, g->mouse.cursorTexture.width, g->mouse.cursorTexture.height}, (Vector2){g->mouse.screenPosition.x, g->mouse.screenPosition.y}, WHITE);
EndTextureMode();
BeginDrawing();
ClearBackground(BLACK);
for (int i = 0; i < SHADER_COUNT; i++)
{
RenderPostFX(&g->postFX[i], &g->target);
}
DrawText(TextFormat("Flower Seeds: %d", g->player.inventar.flowerSeedCount), 10, 10, 50, WHITE);
if (flags->showFPS)
{
@@ -162,7 +143,6 @@ void CleanupGame(GameState *g)
UnloadMusicStream(g->soundtracks[i].music);
}
UnloadRenderTexture(g->target);
FreeArray(&g->flowers);
}
#endif // GAME_H