big refactor

This commit is contained in:
huaqo-games
2025-10-30 22:55:47 +01:00
parent 66b961d7ab
commit 8761c69cfa
395 changed files with 291 additions and 995 deletions
+9 -10
View File
@@ -1,16 +1,15 @@
#ifndef APP_H
#define APP_H
#include <config.h>
#include <window.h>
#include <engine.h>
#include "view.h"
#include "state.h"
#include "flags.h"
#include "font.h"
#include "logo.h"
#include "menu.h"
#include "game.h"
#include "appState.h"
#include "appSettings.h"
#include "appColors.h"
#include "appLogo.h"
#include "appMenu.h"
#include "appGame.h"
typedef struct {
Config config;
@@ -34,7 +33,7 @@ void ConfigApp(App* app){
}
void InitApp(App *app){
InitFont(&app->font);
InitFont(&app->font, "assets/pixelFont-7-8x14-sproutLands.fnt");
InitLogo(&app->logo);
InitMenu(&app->menu);
InitGame(&app->game,&app->window);
+3 -3
View File
@@ -1,7 +1,7 @@
#ifndef COLORS_H
#define COLORS_H
#ifndef APPCOLORS_H
#define APPCOLORS_H
#define TEXT_COLOR_DARK (Color){ 182, 137, 98, 255}
#define TEXT_COLOR_LIGHT (Color){ 243, 229, 194, 255}
#endif // COLORS_H
#endif // APPCOLORS_H
+30 -45
View File
@@ -1,26 +1,21 @@
#ifndef GAME_H
#define GAME_H
#ifndef APPGAME_H
#define APPGAME_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 "appGameFloor.h"
#include "appGamePlayer.h"
#include "appGameBirds.h"
#include "appGameAssets.h"
typedef struct
{
Assets assets;
Texture2D textures[TEX_COUNT];
Assets assets;
PostProcessing postFX[SHADER_COUNT];
Soundtrack soundtracks[SOUNDTRACK_COUNT];
RenderTexture2D target;
Floor floor;
Player player;
Birds birds;
Camera2D camera;
Mouse mouse;
Image image;
@@ -28,34 +23,29 @@ typedef struct
void InitGame(GameState *g, Window *window)
{
g->assets = (Assets){
.shaderAssets = shaderAssets,
.soundtrackAssets = soundtrackAssets
};
g->assets = (Assets){
.textureAssets = texAssets,
.shaderAssets = shaderAssets,
.soundtrackAssets = soundtrackAssets};
for (int i = 0; i < SHADER_COUNT; i++)
{
g->postFX[i] = CreatePostFX(g->assets.shaderAssets[i].path);
}
for (int i = 0; i < TEX_COUNT; i++)
{
g->textures[i] = LoadTexture(g->assets.textureAssets[i].path);
}
for (int i = 0; i < SOUNDTRACK_COUNT; i++)
{
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
}
for (int i = 0; i < SHADER_COUNT; i++)
{
g->postFX[i] = CreatePostFX(g->assets.shaderAssets[i].path);
}
g->target = LoadRenderTexture(window->width, window->height);
g->player = CreatePlayer();
g->birds = CreateBirds();
g->floor = CreateFloor();
g->camera = CreateCamera(g->player.physics.position, 10.0f);
for (int i = 0; i < SOUNDTRACK_COUNT; i++)
{
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
}
g->target = LoadRenderTexture(window->width, window->height);
g->player = CreatePlayer();
g->floor = CreateFloor();
g->camera = CreateCamera(window->width, window->height, g->player.physics.position, 10.0f);
Texture2D mouseTexture = LoadTexture("assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png");
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &mouseTexture);
Texture2D mouseTexture = LoadTexture("assets/mouse.png");
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &mouseTexture);
}
void UpdateGame(GameState *g, State *state, Flags *flags)
@@ -92,12 +82,14 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
UpdateCamera2D(&g->camera, &g->player.physics.position, &g->mouse);
UpdateFloor(&g->floor, &g->camera);
UpdatePlayer(&g->player);
UpdateBirds(&g->birds);
}
void RenderComponents(GameState *g)
{
RenderFloor(&g->floor);
RenderPlayer(&g->player);
RenderBirds(&g->birds);
}
void RenderGame(GameState *g, const State *appState, Flags *flags)
@@ -131,13 +123,6 @@ void CleanupGame(GameState *g)
{
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);
@@ -145,4 +130,4 @@ void CleanupGame(GameState *g)
UnloadRenderTexture(g->target);
}
#endif // GAME_H
#endif // APPGAME_H
+25
View File
@@ -0,0 +1,25 @@
#ifndef APPGAMEASSETS_H
#define APPGAMEASSETS_H
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/sea.mp3"}};
#endif // APPGAMEASSETS_H
+71
View File
@@ -0,0 +1,71 @@
#ifndef APPGAMEBIRDS_H
#define APPGAMEBIRDS_H
typedef struct {
Sprite sprite;
Animation animation;
Physics physics;
} Birds;
typedef enum
{
FLYING,
BIRDS_TEX_COUNT
} birdsTextureID;
const TextureAsset birdsTextureAssets[BIRDS_TEX_COUNT] = {
{"assets/birds.png", 16.0f, 16.0f, 0.0f}
};
Birds CreateBirds(void){
TextureAsset flyingAsset = birdsTextureAssets[FLYING];
Texture2D texture = LoadTexture(flyingAsset.path);
float frameWidth = flyingAsset.frameWidth;
float rotation = flyingAsset.rotation;
Sprite birdSprite = {
.texture = texture,
.frameSize = {frameWidth, frameWidth},
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
.destRec = {GetScreenWidth()/2, 0.0f, frameWidth, frameWidth},
.origin = {frameWidth / 2, frameWidth / 2},
.rotation = rotation,
.color = WHITE
};
Animation birdsAnimation = {
.state = 1,
.currentFrame = 0,
.maxFrame = 2,
.framesCounter = 0,
.framesSpeed = 2.0f,
.animTimer = 0.0f
};
Physics birdsPhysics = {
.position = (Vector2){-100.0f, 0.0f},
.direction = (Vector2){0.0f, 0.0f},
.speed = 10.0f
};
return (Birds){
.sprite = birdSprite,
.animation = birdsAnimation,
.physics = birdsPhysics
};
}
void UpdateBirds(Birds *birds){
UpdatePhysics(&birds->physics, (Vector2){1.0f,0.0f});
UpdateSpriteDestRec(&birds->sprite, &birds->physics.position);
UpdateAnimation(&birds->animation, GetFrameTime());
UpdateSpriteSourceRec(&birds->sprite, &(Vector2){birds->sprite.frameSize.x * birds->animation.currentFrame, birds->sprite.frameSize.y});
}
void RenderBirds(Birds *birds){
RenderSprite(&birds->sprite);
}
#endif // APPGAMEBIRDS_H
+13 -38
View File
@@ -1,8 +1,6 @@
#ifndef Floor_H
#define Floor_H
#ifndef APPGAMEFloor_H
#define APPGAMEFloor_H
#include <raylib.h>
#include <sprite.h>
typedef struct
{
@@ -12,19 +10,15 @@ typedef struct
float time;
} Floor;
// ----------------------------------------------------
// Create floor (loads shader and sets defaults)
// ----------------------------------------------------
Floor CreateFloor()
Floor CreateFloor(void)
{
Texture2D base = LoadTexture("assets/ocean_base.png");
Texture2D caustic = LoadTexture("assets/CausticTexture.png");
Texture2D causticHighlight = LoadTexture("assets/CausticTextureHighlights.png");
Texture2D noise = LoadTexture("assets/noiseTexture.png");
Texture2D cloud = LoadTexture("assets/cloudnoise_1.png");
Texture2D voronoise = LoadTexture("assets/voronoise_3.png");
Texture2D base = LoadTexture("assets/water_base.png");
Texture2D caustic = LoadTexture("assets/water_caustics.png");
Texture2D causticHighlight = LoadTexture("assets/water_caustics_highlights.png");
Texture2D noise = LoadTexture("assets/water_noise.png");
Texture2D cloud = LoadTexture("assets/water_cloudnoise.png");
Texture2D voronoise = LoadTexture("assets/water_voronoise.png");
float textureWidth = 64.0f;
@@ -42,19 +36,14 @@ Floor CreateFloor()
.time = 0.0f
};
float worldTileSize = 128.0f; // one tile covers 128x128 world units
float textureSize = 32.0f; // texture is 32x32 pixels
float worldTileSize = 128.0f;
float textureSize = 32.0f;
floor.sprite.frameSize = (Vector2){worldTileSize, worldTileSize};
floor.sprite.sourceRec = (Rectangle){0, 0, textureSize, textureSize};
floor.sprite.destRec = (Rectangle){0, 0, worldTileSize, worldTileSize};
floor.sprite.origin = (Vector2){0, 0};
// Optional: load your extra water textures here and bind them
// Example:
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticTexture"), caustic);
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticHighlightTexture"), causticHighlight);
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticNoiseTexture"), noise);
@@ -63,11 +52,6 @@ Floor CreateFloor()
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "specularMovementLeftNoiseTexture"), voronoise);
SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "specularMovementRightNoiseTexture"), cloud);
// Texture2D caustic = LoadTexture("resources/caustic.png");
// SetShaderValueTexture(floor.shader, GetShaderLocation(floor.shader, "causticTexture"), caustic);
// Setup aspect ratio and pixelization uniforms once
float aspect = (float)GetScreenHeight() / (float)GetScreenWidth();
float pixelization = 2048.0f;
int aspectLoc = GetShaderLocation(floor.shader, "aspectRatio");
@@ -80,9 +64,6 @@ Floor CreateFloor()
return floor;
}
// ----------------------------------------------------
// Update visible area (same logic as before)
// ----------------------------------------------------
void UpdateFloor(Floor *floor, const Camera2D *camera)
{
floor->bounds.x = (int)((camera->target.x - (GetScreenWidth() / 2.0f / camera->zoom)) / floor->sprite.frameSize.x) - 1;
@@ -90,15 +71,11 @@ void UpdateFloor(Floor *floor, const Camera2D *camera)
floor->bounds.y = (int)((camera->target.y - (GetScreenHeight() / 2.0f / camera->zoom)) / floor->sprite.frameSize.y) - 1;
floor->bounds.height = (int)((camera->target.y + (GetScreenHeight() / 2.0f / camera->zoom)) / floor->sprite.frameSize.y) + 1;
// Update time uniform
floor->time += GetFrameTime();
int timeLoc = GetShaderLocation(floor->shader, "time");
SetShaderValue(floor->shader, timeLoc, &floor->time, SHADER_UNIFORM_FLOAT);
}
// ----------------------------------------------------
// Render floor tiles using the shader
// ----------------------------------------------------
void RenderFloor(Floor *floor)
{
BeginShaderMode(floor->shader);
@@ -116,12 +93,10 @@ void RenderFloor(Floor *floor)
EndShaderMode();
}
// ----------------------------------------------------
// Cleanup
// ----------------------------------------------------
void UnloadFloor(Floor *floor)
{
UnloadShader(floor->shader);
}
#endif // Floor_H
#endif // APPGAMEFLOOR_H
+23 -30
View File
@@ -1,13 +1,5 @@
#ifndef PLAYER_H
#define PLAYER_H
#include <sprite.h>
#include <animation.h>
#include <physics.h>
#include <input.h>
#include <asset.h>
#include "inventar.h"
#ifndef APPGAMEPLAYER_H
#define APPGAMEPLAYER_H
typedef enum
{
@@ -15,12 +7,10 @@ typedef enum
PLAYER_TEX_COUNT
} playerTextureID;
const TextureAsset textureAssets[PLAYER_TEX_COUNT] = {
{"assets/start_ship.png", 16.0f, 16.0f, 0.0f}
const TextureAsset playerTextureAssets[PLAYER_TEX_COUNT] = {
{"assets/ship_start.png", 16.0f, 16.0f, 0.0f}
};
typedef enum {
ANCHOR,
SLOW_AHEAD,
@@ -34,6 +24,15 @@ float playerSpeeds[SPEED_COUNT] = {
10.0f
};
playerSpeedID GetPlayerSpeedID(float speed) {
for (int i = 0; i < SPEED_COUNT; i++) {
if (playerSpeeds[i] == speed) {
return (playerSpeedID)i;
}
}
return ANCHOR;
}
typedef struct
{
@@ -46,7 +45,7 @@ typedef struct
Player CreatePlayer(void)
{
TextureAsset startShipAsset = textureAssets[START_SHIP];
TextureAsset startShipAsset = playerTextureAssets[START_SHIP];
Texture2D texture = LoadTexture(startShipAsset.path);
float frameWidth = startShipAsset.frameWidth;
@@ -79,28 +78,24 @@ Player CreatePlayer(void)
};
return (Player){
.sprite = playerSprite,
.animation = playerAnimation,
.physics = playerPhysics,
.rotation = rotation
return (Player){
.sprite = playerSprite,
.animation = playerAnimation,
.physics = playerPhysics,
.rotation = rotation
};
}
void UpdatePlayer(Player *player)
{
if(IsKeyPressed(KEY_W) || IsKeyPressed(KEY_UP)){
if(player->physics.speed < playerSpeeds[FAST_AHEAD]){
if(player->physics.speed < playerSpeeds[SLOW_AHEAD]){
player->physics.speed = playerSpeeds[SLOW_AHEAD];
player->sprite.sourceRec.x = 16.0f * 1;
}
else {
player->physics.speed = playerSpeeds[FAST_AHEAD];
player->sprite.sourceRec.x = 16.0f * 2;
}
}
}
@@ -109,18 +104,18 @@ void UpdatePlayer(Player *player)
if(player->physics.speed > playerSpeeds[ANCHOR]){
if(player->physics.speed > playerSpeeds[SLOW_AHEAD]){
player->physics.speed = playerSpeeds[SLOW_AHEAD];
player->sprite.sourceRec.x = 16.0f * 1;
}
else {
player->physics.speed = playerSpeeds[ANCHOR];
player->sprite.sourceRec.x = 16.0f * 0;
}
}
}
player->sprite.sourceRec.x = 16.0f * GetPlayerSpeedID(player->physics.speed);
float rotationSpeed = 100.0f;
float rotationSpeed = 50.0f;
if (player->physics.speed > playerSpeeds[ANCHOR]){
@@ -141,12 +136,10 @@ void UpdatePlayer(Player *player)
UpdatePhysics(&player->physics, dir);
UpdateSpriteDestRec(&player->sprite, &player->physics.position);
//UpdateAnimation(&player->animation, GetFrameTime());
//UpdateSpriteSourceRec(&player->sprite, &(Vector2){player->sprite.frameSize.x * player->animation.currentFrame, player->sprite.frameSize.y * player->animation.state});
}
void RenderPlayer(Player *player){
RenderSprite(&player->sprite);
}
#endif // PLAYER_H
#endif // APPGAMEPLAYER_H
+3 -3
View File
@@ -1,5 +1,5 @@
#ifndef LOGO_H
#define LOGO_H
#ifndef APPLOGO_H
#define APPLOGO_H
typedef struct {
int frameCounter;
@@ -114,4 +114,4 @@ void RenderLogo(const LogoState *l, Flags *flags) {
EndDrawing();
}
#endif // LOGO_H
#endif // APPLOGO_H
+6 -6
View File
@@ -1,9 +1,9 @@
#ifndef MENU_H
#define MENU_H
#ifndef APPMENU_H
#define APPMENU_H
#include <menuview.h>
#include <menusettings.h>
#include <menumain.h>
#include <appMenuView.h>
#include <appMenuSettings.h>
#include <appMenuMain.h>
typedef struct
{
@@ -59,4 +59,4 @@ void CleanupMenu(MenuState *m)
CleanupMenuMain(&m->menuMain);
}
#endif // MENU_H
#endif // APPMENU_H
+43
View File
@@ -0,0 +1,43 @@
#ifndef APPMENUASSETS_H
#define APPMENUASSETS_H
typedef enum
{
MENU_CURSOR_TEX,
MENU_BIG_BUTTONS_TEX,
MENU_BOARD_TEX,
MENU_CLOUD_BACKGROUND,
MENU_CLOUD_MIDGROUND,
MENU_CLOUD_FOREGROUND,
MENU_TEX_COUNT
} MenuTextureID;
const TextureAsset menuTextureAssets[MENU_TEX_COUNT] = {
{"assets/mouse.png", 16.0f, 16.0f, 0.0f},
{"assets/buttons.png", 288.0f/3, 96.0f/3, 0.0f},
{"assets/menu_board.png", 128.0f, 144.0f, 0.0f},
{"assets/cloud_background.png", 576.0f, 324.0f, 0.0f},
{"assets/cloud_midground.png", 576.0f, 324.0f, 0.0f},
{"assets/cloud_foreground.png", 576.0f, 324.0f, 0.0f}};
typedef enum
{
MENU_MUSIC,
MENU_SOUNDTRACK_COUNT
} MenuSoundtrackID;
const SoundtrackAsset menuSoundtrackAssets[MENU_SOUNDTRACK_COUNT] = {
{"assets/merrygoround.wav"}};
typedef enum
{
HOVER_SOUND,
CLICK_SOUND,
MENU_SOUND_COUNT
} MenuSoundID;
const SoundAsset menuSoundAssets[MENU_SOUND_COUNT] = {
{"assets/button_hover.wav"},
{"assets/button_click.wav"}};
#endif // APPMENUASSETS_H
+6 -13
View File
@@ -1,16 +1,9 @@
#ifndef MENUMAIN_H
#define MENUMAIN_H
#include <gui.h>
#include <asset.h>
#include <gamegui.h>
#include <input.h>
#include <soundtrack.h>
#include "menuassets.h"
#include "menuview.h"
#include "colors.h"
#include "background.h"
#ifndef APPMENUMAIN_H
#define APPMENUMAIN_H
#include "appMenuAssets.h"
#include "appMenuView.h"
#include "appMenuMainBackground.h"
typedef struct {
Assets assets;
@@ -215,4 +208,4 @@ void CleanupMenuMain(MenuMain *m){
}
}
#endif //MENUMAIN_H
#endif //APPMENUMAIN_H
@@ -1,7 +1,5 @@
#ifndef BACKGROUND_H
#define BACKGROUND_H
#include <sprite.h>
#include <raylib.h>
#ifndef APPMENUMAINBACKGROUND_H
#define APPMENUMAINBACKGROUND_H
typedef struct {
Sprite sprite;
@@ -67,4 +65,4 @@ void RenderBackground(Background *bg){
}
#endif // BACKGROUND_H
#endif // APPMENUMAINBACKGROUND_H
@@ -1,10 +1,6 @@
#ifndef SETTINGS_H
#define SETTINGS_H
#ifndef APPMENUSETTINGS_H
#define APPMENUSETTINGS_H
#include <gui.h>
#include <input.h>
#include <flags.h>
#include "menuview.h"
typedef struct
{
@@ -69,4 +65,4 @@ void ClenupMenuSettings(MenuSettings *s){
}
#endif // SETTINGS_H
#endif // APPMENUSETTINGS_H
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef MENUVIEW_H
#define MENUVIEW_H
#ifndef APPMENUVIEW_H
#define APPMENUVIEW_H
typedef enum MenuView {
MAIN = 0,
+9
View File
@@ -0,0 +1,9 @@
#ifndef APPSETTINGS_H
#define APPSETTINGS_H
typedef struct {
bool showFPS;
bool soundtrackOn;
} Flags;
#endif // APPSETTINGS_H
+16
View File
@@ -0,0 +1,16 @@
#ifndef APPSTATE_H
#define APPSTATE_H
typedef enum View {
LOGO = 0,
MENU = 1,
GAMEPLAY = 2
} View;
typedef struct {
View currentView;
bool running;
bool gameStarted;
} State;
#endif // APPSTATE_H
-76
View File
@@ -1,76 +0,0 @@
#ifndef BEE_H
#define BEE_H
#include <sprite.h>
#include <animation.h>
#include <physics.h>
#include <object.h>
typedef enum {
FLYING
} BeeAnimationState;
typedef struct {
Sprite sprite;
Animation animation;
Physics physics;
Object target;
Object hive;
int flowerCount;
} Bee;
Bee CreateBee(BeeAnimationState animState, Texture2D texture, float frameWidth, int maxFrame, int framesSpeed, Vector2 position, float speed, ObjectArray* target, Object* base){
return (Bee){
.sprite = {
.texture = texture,
.frameSize = {frameWidth, frameWidth},
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
.destRec = {0.0f, 0.0f, frameWidth, frameWidth},
.origin = {frameWidth / 2, frameWidth / 2},
.rotation = 0.0f,
.color = WHITE
},
.animation = {
.state = animState,
.currentFrame = 0,
.maxFrame = maxFrame,
.framesCounter = 0,
.framesSpeed = framesSpeed,
.animTimer = 0.0f
},
.physics = {
.position = position,
.direction = (Vector2){0.0f,0.0f},
.speed = speed
},
.target = *GetRandomObject(target),
.hive = *base
};
}
void UpdateBee(Bee* bee, ObjectArray* flowers, Object* hive){
const float tolerance = 1.0f;
if (bee->flowerCount < 4){
if (fabs(bee->physics.position.x - bee->target.position.x) < tolerance &&
fabs(bee->physics.position.y - bee->target.position.y) < tolerance) {
bee->target = *GetRandomObject(flowers);
bee->flowerCount++;
} else {
}
} else {
bee->target = *hive;
if (fabs(bee->physics.position.x - bee->target.position.x) < tolerance &&
fabs(bee->physics.position.y - bee->target.position.y) < tolerance) {
bee->physics.speed = 0.0f;
} else {
}
}
UpdatePhysics(&bee->physics, GetDirectionToObject(&bee->target, bee->physics.position));
UpdateSpriteRotation(&bee->sprite, &bee->physics.direction);
UpdateSpriteDestRec(&bee->sprite, &bee->physics.position);
UpdateAnimation(&bee->animation, GetFrameTime());
UpdateSpriteSourceRec(&bee->sprite, &(Vector2){bee->sprite.frameSize.x * bee->animation.state, bee->sprite.frameSize.x * bee->animation.currentFrame});
}
#endif // BEE_H
-20
View File
@@ -1,20 +0,0 @@
// initButton(&m->startButton, "Start Game", GetScreenWidth() / 10, GetScreenHeight() / 20, GetScreenWidth() / 2, GetScreenHeight() / 2);
// initButton(&m->quitButton, "Quit Game", GetScreenWidth() / 10, GetScreenHeight() / 20, GetScreenWidth() / 2,
// GetScreenHeight() / 2 + (GetScreenHeight() / 20 * 2));
// if (isButtonClicked(&m->startButton)) {
// state->gameStarted = true;
// m->startButton.text = "Continue";
// state->currentScreen = GAMEPLAY;
// }
// if (isButtonClicked(&m->quitButton) || (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))) {
// state->running = false;
// }
// if (state->gameStarted){
// if (IsKeyPressed(KEY_ESCAPE)){
// state->currentScreen = GAMEPLAY;
// }
// }
// renderButton(&m->startButton);
// renderButton(&m->quitButton);
-9
View File
@@ -1,9 +0,0 @@
#ifndef FLAGS_H
#define FLAGS_H
typedef struct {
bool showFPS;
bool soundtrackOn;
} Flags;
#endif // FLAGS_H
-87
View File
@@ -1,87 +0,0 @@
#ifndef FLOWERS_H
#define FLOWERS_H
#include "array.h"
typedef enum {
CHILD,
TEEN,
ADULT
} AGE;
typedef struct {
Sprite sprite;
Vector2 position;
AGE age;
float ageTimer;
} Flower;
Flower DEFAULT_FLOWER;
Array* CreateFlowers(Texture2D texture, float frameWidth, float rotation, float fieldSize)
{
Array* flowers = CreateArray(10);
if(!flowers) {
printf("Memory allocation failed.\n");
exit(1);
}
DEFAULT_FLOWER = (Flower){
.sprite = {
.texture = texture,
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
.destRec = {(float)GetRandomValue(-fieldSize,fieldSize), (float)GetRandomValue(-fieldSize,fieldSize), frameWidth, frameWidth},
.origin = {frameWidth / 2, frameWidth / 2},
.rotation = rotation,
.color = WHITE,
},
.age = CHILD,
.ageTimer = 0.0f
};
for (int i = 0; i < 10; i++) {
Flower* flower = malloc(sizeof(Flower));
*flower = DEFAULT_FLOWER;
flower->sprite.destRec = (Rectangle){(float)GetRandomValue(-fieldSize,fieldSize), (float)GetRandomValue(-fieldSize,fieldSize), frameWidth, frameWidth};
AddElementToArray(flowers, flower);
}
return flowers;
}
void AddFlower(Array* flowers, Rectangle rec){
Flower* flower = malloc(sizeof(Flower));
*flower = DEFAULT_FLOWER;
flower->sprite.destRec = rec;
AddElementToArray(flowers, flower);
}
void UpdateFlower(void* element) {
Flower* f = (Flower*)element;
if (!f) return;
f->ageTimer += 1;
if (f->age == CHILD && f->ageTimer >= 3000.0f) {
f->age = TEEN;
f->sprite.sourceRec.x = f->sprite.sourceRec.width;
}
else if (f->age == TEEN && f->ageTimer >= 6000.0f) {
f->age = ADULT;
f->sprite.sourceRec.x = 2.0f * f->sprite.sourceRec.width;
}
}
void RenderFlower(void* element)
{
Flower* f = (Flower*)element;
if (!f) return;
RenderSprite(&(f->sprite));
}
#endif // FLOWERS_H
-13
View File
@@ -1,13 +0,0 @@
#ifndef FONT_H
#define FONT_H
void InitFont(Font *font){
*font = LoadFont("assets/SproutLandsUI/fonts/pixelFont-7-8x14-sproutLands.fnt");
SetTextureFilter(font->texture, TEXTURE_FILTER_POINT);
}
void CleanupFont(Font *font){
UnloadFont(*font);
}
#endif //FONT_H
-54
View File
@@ -1,54 +0,0 @@
#ifndef GAMEASSETS_H
#define GAMEASSETS_H
#include <asset.h>
////////////////////////////////////////////////////////////////////////////
typedef enum
{
PLAYER,
PLAYER_ACTIONS,
TOOLS,
FLOWER,
BEE,
GRASS,
HIVE,
CURSOR,
TEX_COUNT
} TextureID;
const TextureAsset texAssets[TEX_COUNT] = {
{"assets/ship.png", 32.0f, 32.0f, 0.0f},
{"assets/SproutLandsBasic/Characters/BasicCharakterActions.png", 48.0f, 48.0f, 0.0f},
{"assets/SproutLandsBasic/Objects/tools.png", 48.0f, 16.0f, 0.0f},
{"assets/carrot_and_tomato.png", 32.0f, 32.0f, 0.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},
{"assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png", 16.0f, 16.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/sea.mp3"}};
////////////////////////////////////////////////////////////////////////////
#endif // GAMEASSETS_H
-19
View File
@@ -1,19 +0,0 @@
#ifndef GAMEUI
#define GAMEUI
#include "flags.h"
void RenderGameUI(bool showFPS){
BeginDrawing();
ClearBackground(BLACK);
if (showFPS)
{
DrawFPS(10, 10);
}
EndDrawing();
}
#endif //GAMEUI
-18
View File
@@ -1,18 +0,0 @@
#ifndef HIVE_H
#define HIVE_H
#include <object.h>
Object CreateHive(Texture2D texture, float frameWidth)
{
return (Object){
.sprite = {
.texture = texture,
.sourceRec = (Rectangle){0.0f, 0.0f, frameWidth, frameWidth},
.destRec = (Rectangle){0.0f, 0.0f, frameWidth, frameWidth},
.origin = (Vector2){frameWidth / 2, frameWidth / 2},
.rotation = 0.0f,
.color = WHITE},
.position = (Vector2){0.0f, 0.0f}};
}
#endif // HIVE_H
-9
View File
@@ -1,9 +0,0 @@
#ifndef INVENTAR_H
#define INVENTAR_H
typedef struct{
int flowerSeedCount;
} Inventar;
#endif // INVENTAR_H
-44
View File
@@ -1,44 +0,0 @@
#ifndef MENUASSETS_H
#define MENUASSETS_H
#include <asset.h>
typedef enum
{
MENU_CURSOR_TEX,
MENU_BIG_BUTTONS_TEX,
MENU_BOARD_TEX,
MENU_CLOUD_BACKGROUND,
MENU_CLOUD_MIDGROUND,
MENU_CLOUD_FOREGROUND,
MENU_TEX_COUNT
} MenuTextureID;
const TextureAsset menuTextureAssets[MENU_TEX_COUNT] = {
{"assets/SproutLandsUI/Spritesheets/Mouse sprites/TriangleMouseicon1.png", 16.0f, 16.0f, 0.0f},
{"assets/SproutLandsUI/Spritesheets/UIBigPlayButtonHover2.png", 288.0f/3, 96.0f/3, 0.0f},
{"assets/SproutLandsUI/Spritesheets/Settingmenu.png", 128.0f, 144.0f, 0.0f},
{"assets/Clouds/Clouds1/1.png", 576.0f, 324.0f, 0.0f},
{"assets/Clouds/Clouds1/2.png", 576.0f, 324.0f, 0.0f},
{"assets/Clouds/Clouds1/4.png", 576.0f, 324.0f, 0.0f}};
typedef enum
{
MENU_MUSIC,
MENU_SOUNDTRACK_COUNT
} MenuSoundtrackID;
const SoundtrackAsset menuSoundtrackAssets[MENU_SOUNDTRACK_COUNT] = {
{"assets/merrygoround.wav"}};
typedef enum
{
HOVER_SOUND,
CLICK_SOUND,
MENU_SOUND_COUNT
} MenuSoundID;
const SoundAsset menuSoundAssets[MENU_SOUND_COUNT] = {
{"assets/audio/WAV/Minimalist1.wav"},
{"assets/audio/WAV/Abstract1.wav"}};
#endif // MENUASSETS_H
View File
-12
View File
@@ -1,12 +0,0 @@
#ifndef STATE_H
#define STATE_H
#include "view.h"
typedef struct {
View currentView;
bool running;
bool gameStarted;
} State;
#endif // STATE_H
-10
View File
@@ -1,10 +0,0 @@
#ifndef VIEW_H
#define VIEW_H
typedef enum View {
LOGO = 0,
MENU = 1,
GAMEPLAY = 2
} View;
#endif // SCREEN_H