big refactor: i see i need header files

This commit is contained in:
huaqo-games
2025-11-02 11:23:26 +01:00
parent 297a835780
commit c1a2448126
38 changed files with 582 additions and 560 deletions
+2 -2
View File
@@ -29,11 +29,11 @@ EXTERNAL_FLAGS = \
$(EXTERNAL_RAYGUI)
ifeq ($(OS), Windows_NT)
SRC = src\main.c
SRC = $(wildcard src\*.c)
TARGET = bin\win\game.exe
RAYLIB_FLAGS = -I%RAYLIB% -L%RAYLIB% -lraylib -lopengl32 -lgdi32 -lwinmm
else
SRC = src/main.c
SRC = $(wildcard src/*.c)
TARGET = bin/osx/game
RAYLIB_FLAGS = $(shell pkg-config --libs --cflags raylib)
endif
-30
View File
@@ -1,30 +0,0 @@
#ifndef ASSET_H
#define ASSET_H
typedef struct {
const char* path;
float frameWidth;
float frameHeight;
float rotation;
} TextureAsset;
typedef struct {
const char* path;
} ShaderAsset;
typedef struct {
const char* path;
} SoundtrackAsset;
typedef struct {
const char* path;
} SoundAsset;
typedef struct {
const TextureAsset *textureAssets;
const ShaderAsset *shaderAssets;
const SoundtrackAsset *soundtrackAssets;
const SoundAsset *soundAssets;
} Assets;
#endif // ASSET_H
-21
View File
@@ -1,21 +0,0 @@
#ifndef ENGINE_H
#define ENGINE_H
#include "animation.h"
//#include "array.h"
#include "asset.h"
#include "camera.h"
#include "config.h"
#include "gamegui.h"
#include "gui.h"
#include "input.h"
#include "object.h"
#include "physics.h"
#include "postfx.h"
#include "soundtrack.h"
#include "sprite.h"
#include "vector.h"
#include "window.h"
#include "font.h"
#endif //ENGINE_H
-10
View File
@@ -1,10 +0,0 @@
#ifndef DISPLAY_H
#define DISPLAY_H
typedef struct {
int width;
int height;
const char* title;
} Window;
#endif // DISPLAY_H
-7
View File
@@ -1,7 +0,0 @@
#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 // APPCOLORS_H
-25
View File
@@ -1,25 +0,0 @@
#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
-43
View File
@@ -1,43 +0,0 @@
#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
-10
View File
@@ -1,10 +0,0 @@
#ifndef APPMENUVIEW_H
#define APPMENUVIEW_H
typedef enum MenuView {
MAIN = 0,
SETTINGS = 1
} MenuView;
#endif // MENUVIEW_H
-9
View File
@@ -1,9 +0,0 @@
#ifndef APPSETTINGS_H
#define APPSETTINGS_H
typedef struct {
bool showFPS;
bool soundtrackOn;
} Flags;
#endif // APPSETTINGS_H
-16
View File
@@ -1,16 +0,0 @@
#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
+257
View File
@@ -0,0 +1,257 @@
#ifndef APPTYPES_H
#define APPTYPES_H
//INCLUDES//
#include <raylib.h>
#include <engine.h>
//DEFINES//
#define TEXT_COLOR_DARK (Color){ 182, 137, 98, 255}
#define TEXT_COLOR_LIGHT (Color){ 243, 229, 194, 255}
//ENUMS//
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;
typedef enum
{
MENU_MUSIC,
MENU_SOUNDTRACK_COUNT
} MenuSoundtrackID;
typedef enum
{
HOVER_SOUND,
CLICK_SOUND,
MENU_SOUND_COUNT
} MenuSoundID;
typedef enum MenuView {
MAIN = 0,
SETTINGS = 1
} MenuView;
typedef enum
{
START_SHIP,
PLAYER_TEX_COUNT
} playerTextureID;
typedef enum {
ANCHOR,
SLOW_AHEAD,
FAST_AHEAD,
SPEED_COUNT
} playerSpeedID;
typedef enum
{
FLYING,
BIRDS_TEX_COUNT
} birdsTextureID;
typedef enum
{
ISLAND,
ISLANDS_TEX_COUNT
} islandsTextureID;
typedef enum
{
POST_FX,
SHADER_COUNT
} ShaderID;
typedef enum
{
BEE_AMBIENT,
SOUNDTRACK_COUNT
} SoundtrackID;
typedef enum View {
LOGO = 0,
MENU = 1,
GAMEPLAY = 2
} View;
//STRUCTS//
typedef struct {
int frameCounter;
int positionX;
int positionY;
int lettersCount;
int topSideRecWidth;
int leftSideRecHeight;
int bottomSideRecWidth;
int rightSideRecHeight;
int state;
float alpha;
} LogoState;
typedef struct {
Sprite sprite;
float scrolling;
float scale;
float scrollSpeed;
Vector2 pos;
} Background;
typedef struct {
Assets assets;
Mouse mouse;
Texture2D textures[MENU_TEX_COUNT];
Sound sounds[MENU_SOUND_COUNT];
Soundtrack soundtracks[MENU_SOUNDTRACK_COUNT];
ImageElement board;
ImageButton playButton;
ImageButton quitButton;
ImageButton settingsButton;
int menuScale;
Background background;
Background midground;
Background foreground;
} MenuMain;
typedef struct
{
Button showFPS;
Button soundtrackOn;
} MenuSettings;
typedef struct
{
MenuView menuView;
MenuMain menuMain;
MenuSettings menuSettings;
} MenuState;
typedef struct
{
Sprite sprite;
Rectangle bounds;
Shader shader;
float time;
} Floor;
typedef struct
{
Sprite sprite;
Animation animation;
Physics physics;
float rotation;
} Player;
typedef struct {
Sprite sprite;
Animation animation;
Physics physics;
} Birds;
typedef struct {
Sprite sprite;
Animation animation;
Physics physics;
} Islands;
typedef struct
{
Assets assets;
PostProcessing postFX[SHADER_COUNT];
Soundtrack soundtracks[SOUNDTRACK_COUNT];
RenderTexture2D target;
Floor floor;
Player player;
Birds birds;
Islands islands;
Camera2D camera;
Mouse mouse;
Image image;
} GameState;
typedef struct {
View currentView;
bool running;
bool gameStarted;
} State;
typedef struct {
bool showFPS;
bool soundtrackOn;
} Flags;
typedef struct {
Config config;
State state;
Flags flags;
Window window;
Font font;
LogoState logo;
MenuState menu;
GameState game;
} App;
//FUNCTIONS//
void InitLogo(LogoState *l);
void UpdateLogo(LogoState *l, View *currentView, bool *running);
void RenderLogo(const LogoState *l, Flags *flags);
void InitBackground(float scrollSpeed, Background *bg, Texture2D *texture, const TextureAsset *backgroundAsset);
void UpdateBackground(Background *bg);
void RenderBackground(Background *bg);
void InitMenuMain(MenuMain *m);
void UpdateMenuMain(MenuMain *m, State *state, Flags *flags, MenuView *menuView);
void RenderMenuMain(MenuMain *m, Font *font, const char *title, Flags *flags);
void CleanupMenuMain(MenuMain *m);
void InitMenuSettings(MenuSettings *s);
void UpdateMenuSettings(MenuSettings *s, MenuView *menuView, Flags *flags);
void RenderMenuSettings(MenuSettings *s, Flags *flags);
void CleanupMenuSettings(MenuSettings *s);
void InitMenu(MenuState *m);
void UpdateMenu(MenuState *m, State *state, Flags *flags);
void RenderMenu(MenuState *m, Font *font, const char *title, Flags *flags);
void CleanupMenu(MenuState *m);
Floor CreateFloor(void);
void UpdateFloor(Floor *floor, const Camera2D *camera);
void RenderFloor(Floor *floor);
void UnloadFloor(Floor *floor);
playerSpeedID GetPlayerSpeedID(float speed);
Player CreatePlayer(void);
void UpdatePlayer(Player *player);
void RenderPlayer(Player *player);
Birds CreateBirds(void);
void UpdateBirds(Birds *birds);
void RenderBirds(Birds *birds);
Islands CreateIslands(void);
void UpdateIslands(Islands *islands);
void RenderIslands(Islands *islands);
void InitGame(App *app);
void UpdateGame(App *app);
void RenderComponents(App *app);
void RenderGame(App *app);
void CleanupGame(App *app);
void ConfigApp(App *app);
void InitApp(App *app);
void UpdateApp(App *app);
void CleanupApp(App *app);
#endif //APPTYPES_H
+232
View File
@@ -0,0 +1,232 @@
#ifndef ENGINE_H
#define ENGINE_H
#include <raylib.h>
#include <raymath.h>
#include <raygui.h>
#include <rini.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <math.h>
typedef struct
{
Texture2D texture;
Rectangle sourceRec;
Rectangle destRec;
Vector2 frameSize;
Vector2 origin;
float rotation;
Color color;
} Sprite;
typedef struct {
int state;
int currentFrame;
int maxFrame;
int framesCounter;
int framesSpeed;
float animTimer;
} Animation;
typedef struct {
void** elements;
unsigned int count;
unsigned int capacity;
} Array;
typedef struct {
const char* path;
float frameWidth;
float frameHeight;
float rotation;
} TextureAsset;
typedef struct {
const char* path;
} ShaderAsset;
typedef struct {
const char* path;
} SoundtrackAsset;
typedef struct {
const char* path;
} SoundAsset;
typedef struct {
const TextureAsset *textureAssets;
const ShaderAsset *shaderAssets;
const SoundtrackAsset *soundtrackAssets;
const SoundAsset *soundAssets;
} Assets;
typedef struct {
char *path;
rini_config rini;
} Config;
typedef enum {
NOT_CLICKED,
HOVER,
CLICKED
} ButtonState;
typedef struct
{
Sprite sprite;
Vector2 notClicked;
Vector2 hover;
Vector2 clicked;
bool isHovered;
bool isClicked;
} ImageButton;
typedef struct
{
Sprite sprite;
} ImageElement;
typedef struct
{
Rectangle rec;
char *text;
} Button;
typedef struct {
Vector2 screenPosition;
Vector2 worldPosition;
float zoomSpeed;
float minZoom;
float maxZoom;
float scaleFactor;
float wheelMove;
bool leftButton;
bool rightButton;
Texture2D cursorTexture;
} Mouse;
typedef struct {
Sprite sprite;
Vector2 position;
} Object;
typedef struct {
Object *data;
const Object *prototype;
size_t count;
} ObjectArray;
typedef struct
{
Vector2 position;
Vector2 direction;
Vector2 velocity;
float speed;
} Physics;
typedef struct {
Shader shader;
int resolutionLoc;
int strengthLoc;
float strength;
} PostProcessing;
typedef struct {
Music music;
bool playing;
bool paused;
} Soundtrack;
typedef struct {
Vector2 *data;
size_t count;
} Vector2Array;
typedef struct {
int width;
int height;
const char* title;
} Window;
void UpdateAnimation(Animation *animation, float deltaTime);
Array* CreateArray(unsigned int initCapacity);
int AddElementToArray(Array* array, void* element);
int RemoveElementFromArray(Array* array, unsigned int index);
void* GetRandomElementFromArray(Array* array);
void UpdateArray(Array* array, void (*updateFunc)(void*));
void RenderArray(Array* array, void (*renderFunc)(void*));
void FreeArray(Array** array);
Camera2D CreateCamera(Vector2 playerPosition, float initZoom);
void UpdateCameraTarget(Camera2D *camera, Vector2 *position, const float smoothness);
void UpdateCameraZoom(Camera2D *camera, const float *scaleFactor, const float *minZoom, const float *maxZoom);
void UpdateCamera2D(Camera2D* camera, Vector2* position, Mouse* mouse);
void InitConfig(Config *config, const char* path);
int GetConfigInt(Config *config, const char *key);
int GetConfigIntOrDefault(Config *config, const char *key, int default_value);
const char* GetConfigString(Config *config, const char *key);
const char* GetConfigStringOrDefault(Config *config, const char *key, const char *default_value);
const char* GetConfigDescription(Config *config, const char *key);
int SetConfigInt(Config *config, const char *key, int value, const char *desc);
int SetConfigString(Config *config, const char *key, const char *text, const char *desc);
int SetConfigDescription(Config *config, const char *key, const char *desc);
int AddCommentLine(Config *config, const char *comment);
void SaveConfig(Config *config);
void CleanUpConfig(Config *config);
void InitFont(Font *font, const char* path);
void CleanupFont(Font *font);
ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Vector2 *hover, Rectangle *destRec);
ImageElement CreateImageElement(Texture2D *texture, const TextureAsset *asset, Vector2 *source, Rectangle *destRec);
int isImageButtonClicked(ImageButton *b, Sound soundHover, Sound soundClick);
void renderImageButton(ImageButton *b);
void renderImageElement(ImageElement *e);
Button initButton(char *text, Vector2 dimensions, Vector2 position);
int isButtonClicked(Button *b);
void renderButton(Button *b);
Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom, Texture2D *texture);
void UpdateMouseScreen(Mouse *mouse);
void UpdateMouse(Mouse *mouse, Camera2D *camera);
Vector2 GetDirectionVector(void);
ObjectArray CreateObjectArray(const Object *prototype, const size_t count);
Object* GetRandomObject(ObjectArray *objects);
void AddObjectToArray(ObjectArray *objects, const Object *prototype, Vector2 position);
void SetPositionForObjectArray(ObjectArray *objects, const Vector2Array *positions);
void SetRandomPositionForObjectArray(ObjectArray *objects, const Rectangle bounds);
void SwapAndPopObjectsArrayOnRecCollision(ObjectArray *objects, const Rectangle rec);
void SwapAndPopObjectsArrayOnPointCollision(ObjectArray *objects, const Vector2 point);
void RenderObjectArray(const ObjectArray *objects);
void UpdatePhysicsDirection(Vector2 *direction, Vector2 vector);
void UpdatePhysicsVelocity(Vector2 *velocity, Vector2 *direction, float *speed);
void UpdatePhysicsPosition(Vector2 *position, Vector2 *velocity);
void UpdatePhysicsSpeed(float *speed, float *newSpeed);
void UpdatePhysics(Physics *physics, Vector2 direction);
PostProcessing CreatePostFX(const char* shaderPath);
void UpdatePostFX(PostProcessing *postFX);
void RenderPostFX(PostProcessing *postFX, RenderTexture2D *target);
void UnloadPostFX(PostProcessing *postFX);
Soundtrack LoadSoundtrack(const char* musicPath);
void UpdateSoundtrack(Soundtrack *soundtrack, bool playing);
void UpdateSpriteSourceRec(Sprite *sprite, const Vector2 *vector);
void UpdateSpriteDestRec(Sprite *sprite, const Vector2 *vector);
void UpdateSpriteRotation(Sprite *sprite, Vector2 *vector);
void RenderSprite(const Sprite *sprite);
void PrintSprite(const Sprite *sprite);
bool IsVectorZero(Vector2 v);
Vector2 GetRandomVector(const Rectangle bounds);
#endif //ENGINE_H
+5 -26
View File
@@ -1,26 +1,6 @@
#ifndef APP_H
#define APP_H
#include <engine.h>
#include "appState.h"
#include "appSettings.h"
#include "appColors.h"
#include "appLogo.h"
#include "appMenu.h"
#include "appGame.h"
typedef struct {
Config config;
State state;
Flags flags;
Window window;
Font font;
LogoState logo;
MenuState menu;
GameState game;
} App;
#include "appTypes.h"
void ConfigApp(App* app){
InitConfig(&app->config, "config/config.ini");
@@ -36,7 +16,7 @@ void InitApp(App *app){
InitFont(&app->font, "assets/font.fnt");
InitLogo(&app->logo);
InitMenu(&app->menu);
InitGame(&app->game,&app->window);
InitGame(app);
}
void UpdateApp(App *app){
@@ -60,8 +40,8 @@ void UpdateApp(App *app){
}break;
case GAMEPLAY:
{
UpdateGame(&app->game, &app->state, &app->flags);
RenderGame(&app->game, &app->state, &app->flags);
UpdateGame(app);
RenderGame(app);
}break;
default: break;
}
@@ -70,9 +50,8 @@ void UpdateApp(App *app){
void CleanupApp(App *app){
CleanupMenu(&app->menu);
CleanupGame(&app->game);
CleanupGame(app);
CleanupFont(&app->font);
CleanUpConfig(&app->config);
}
#endif //APP_H
+33 -36
View File
@@ -1,30 +1,17 @@
#ifndef APPGAME_H
#define APPGAME_H
#include "appTypes.h"
const ShaderAsset shaderAssets[SHADER_COUNT] = {
{"shaders/postfx.fs"}};
#include "appGameFloor.h"
#include "appGamePlayer.h"
#include "appGameBirds.h"
#include "appGameIslands.h"
#include "appGameAssets.h"
typedef struct
{
Assets assets;
PostProcessing postFX[SHADER_COUNT];
Soundtrack soundtracks[SOUNDTRACK_COUNT];
RenderTexture2D target;
Floor floor;
Player player;
Birds birds;
Islands islands;
Camera2D camera;
Mouse mouse;
Image image;
} GameState;
const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = {
{"assets/sea.mp3"}};
void InitGame(GameState *g, Window *window)
void InitGame(App *app)
{
GameState *g = &app->game;
g->assets = (Assets){
.shaderAssets = shaderAssets,
.soundtrackAssets = soundtrackAssets
@@ -40,7 +27,7 @@ void InitGame(GameState *g, Window *window)
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
}
g->target = LoadRenderTexture(window->width, window->height);
g->target = LoadRenderTexture(app->window.width, app->window.height);
g->player = CreatePlayer();
g->birds = CreateBirds();
g->islands = CreateIslands();
@@ -51,10 +38,11 @@ void InitGame(GameState *g, Window *window)
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &mouseTexture);
}
void UpdateGame(GameState *g, State *state, Flags *flags)
void UpdateGame(App *app)
{
if(!state->gameStarted){
state->gameStarted = true;
GameState *g = &app->game;
if(!app->state.gameStarted){
app->state.gameStarted = true;
}
if (GetFPS() <= 60)
@@ -64,12 +52,12 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
if (IsKeyPressed(KEY_ESCAPE))
{
state->currentView = MENU;
app->state.currentView = MENU;
}
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE))
{
state->running = false;
app->state.running = false;
}
for (int i = 0; i < SHADER_COUNT; i++)
@@ -78,7 +66,7 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
}
for (int i = 0; i < SOUNDTRACK_COUNT; i++)
{
UpdateSoundtrack(&g->soundtracks[i], flags->soundtrackOn);
UpdateSoundtrack(&g->soundtracks[i], app->flags.soundtrackOn);
}
UpdateMouse(&g->mouse, &g->camera);
@@ -89,22 +77,31 @@ void UpdateGame(GameState *g, State *state, Flags *flags)
UpdateIslands(&g->islands);
}
void RenderComponents(GameState *g)
void RenderComponents(App *app)
{
GameState *g = &app->game;
RenderFloor(&g->floor);
RenderPlayer(&g->player);
RenderBirds(&g->birds);
RenderIslands(&g->islands);
}
void RenderGame(GameState *g, const State *appState, Flags *flags)
void RenderGame(App *app)
{
GameState *g = &app->game;
BeginTextureMode(g->target);
ClearBackground(BLACK);
BeginMode2D(g->camera);
RenderComponents(g);
RenderComponents(app);
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);
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();
@@ -114,7 +111,7 @@ void RenderGame(GameState *g, const State *appState, Flags *flags)
RenderPostFX(&g->postFX[i], &g->target);
}
if (flags->showFPS)
if (app->flags.showFPS)
{
DrawFPS(10, 10);
}
@@ -122,8 +119,9 @@ void RenderGame(GameState *g, const State *appState, Flags *flags)
EndDrawing();
}
void CleanupGame(GameState *g)
void CleanupGame(App *app)
{
GameState *g = &app->game;
for (int i = 0; i < SHADER_COUNT; i++)
{
UnloadPostFX(&g->postFX[i]);
@@ -135,4 +133,3 @@ void CleanupGame(GameState *g)
UnloadRenderTexture(g->target);
}
#endif // APPGAME_H
+1 -15
View File
@@ -1,17 +1,4 @@
#ifndef APPGAMEBIRDS_H
#define APPGAMEBIRDS_H
typedef struct {
Sprite sprite;
Animation animation;
Physics physics;
} Birds;
typedef enum
{
FLYING,
BIRDS_TEX_COUNT
} birdsTextureID;
#include "appTypes.h"
const TextureAsset birdsTextureAssets[BIRDS_TEX_COUNT] = {
{"assets/birds.png", 16.0f, 16.0f, 45.0f}
@@ -68,4 +55,3 @@ void RenderBirds(Birds *birds){
RenderSprite(&birds->sprite);
}
#endif // APPGAMEBIRDS_H
+1 -13
View File
@@ -1,14 +1,4 @@
#ifndef APPGAMEFloor_H
#define APPGAMEFloor_H
typedef struct
{
Sprite sprite;
Rectangle bounds;
Shader shader;
float time;
} Floor;
#include "appTypes.h"
Floor CreateFloor(void)
{
@@ -98,5 +88,3 @@ void UnloadFloor(Floor *floor)
UnloadShader(floor->shader);
}
#endif // APPGAMEFLOOR_H
@@ -1,17 +1,4 @@
#ifndef APPGAMEISLANDS_H
#define APPGAMEISLANDS_H
typedef struct {
Sprite sprite;
Animation animation;
Physics physics;
} Islands;
typedef enum
{
ISLAND,
ISLANDS_TEX_COUNT
} islandsTextureID;
#include "appTypes.h"
const TextureAsset islandsTextureAssets[ISLANDS_TEX_COUNT] = {
{"assets/island.png", 16.0f, 16.0f, 0.0f}
@@ -58,5 +45,3 @@ void RenderIslands(Islands *islands){
RenderSprite(&islands->sprite);
}
#endif // APPGAMEISLANDS_H
@@ -1,22 +1,10 @@
#ifndef APPGAMEPLAYER_H
#define APPGAMEPLAYER_H
typedef enum
{
START_SHIP,
PLAYER_TEX_COUNT
} playerTextureID;
#include "appTypes.h"
const TextureAsset playerTextureAssets[PLAYER_TEX_COUNT] = {
{"assets/ship_start.png", 16.0f, 16.0f, 0.0f}
};
typedef enum {
ANCHOR,
SLOW_AHEAD,
FAST_AHEAD,
SPEED_COUNT
} playerSpeedID;
float playerSpeeds[SPEED_COUNT] = {
0.0f,
@@ -33,15 +21,6 @@ playerSpeedID GetPlayerSpeedID(float speed) {
return ANCHOR;
}
typedef struct
{
Sprite sprite;
Animation animation;
Physics physics;
float rotation;
} Player;
Player CreatePlayer(void)
{
@@ -142,4 +121,3 @@ void RenderPlayer(Player *player){
RenderSprite(&player->sprite);
}
#endif // APPGAMEPLAYER_H
+1 -16
View File
@@ -1,18 +1,4 @@
#ifndef APPLOGO_H
#define APPLOGO_H
typedef struct {
int frameCounter;
int positionX;
int positionY;
int lettersCount;
int topSideRecWidth;
int leftSideRecHeight;
int bottomSideRecWidth;
int rightSideRecHeight;
int state;
float alpha;
} LogoState;
#include "appTypes.h"
void InitLogo(LogoState *l) {
SetTargetFPS(60);
@@ -114,4 +100,3 @@ void RenderLogo(const LogoState *l, Flags *flags) {
EndDrawing();
}
#endif // APPLOGO_H
+1 -14
View File
@@ -1,16 +1,4 @@
#ifndef APPMENU_H
#define APPMENU_H
#include <appMenuView.h>
#include <appMenuSettings.h>
#include <appMenuMain.h>
typedef struct
{
MenuView menuView;
MenuMain menuMain;
MenuSettings menuSettings;
} MenuState;
#include "appTypes.h"
void InitMenu(MenuState *m)
{
@@ -59,4 +47,3 @@ void CleanupMenu(MenuState *m)
CleanupMenuMain(&m->menuMain);
}
#endif // APPMENU_H
+18 -21
View File
@@ -1,25 +1,23 @@
#ifndef APPMENUMAIN_H
#define APPMENUMAIN_H
#include "appTypes.h"
#include "appMenuAssets.h"
#include "appMenuView.h"
#include "appMenuMainBackground.h"
typedef struct {
Assets assets;
Mouse mouse;
Texture2D textures[MENU_TEX_COUNT];
Sound sounds[MENU_SOUND_COUNT];
Soundtrack soundtracks[MENU_SOUNDTRACK_COUNT];
ImageElement board;
ImageButton playButton;
ImageButton quitButton;
ImageButton settingsButton;
int menuScale;
Background background;
Background midground;
Background foreground;
} MenuMain;
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}};
const SoundtrackAsset menuSoundtrackAssets[MENU_SOUNDTRACK_COUNT] = {
{"assets/merrygoround.wav"}};
const SoundAsset menuSoundAssets[MENU_SOUND_COUNT] = {
{"assets/button_hover.wav"},
{"assets/button_click.wav"}};
void InitMenuMain(MenuMain *m){
@@ -208,4 +206,3 @@ void CleanupMenuMain(MenuMain *m){
}
}
#endif //APPMENUMAIN_H
@@ -1,13 +1,4 @@
#ifndef APPMENUMAINBACKGROUND_H
#define APPMENUMAINBACKGROUND_H
typedef struct {
Sprite sprite;
float scrolling;
float scale;
float scrollSpeed;
Vector2 pos;
} Background;
#include "appTypes.h"
void InitBackground(float scrollSpeed, Background *bg, Texture2D *texture, const TextureAsset *backgroundAsset){
bg->scrolling = 0.0f;
@@ -65,4 +56,3 @@ void RenderBackground(Background *bg){
}
#endif // APPMENUMAINBACKGROUND_H
@@ -1,13 +1,4 @@
#ifndef APPMENUSETTINGS_H
#define APPMENUSETTINGS_H
typedef struct
{
Button showFPS;
Button soundtrackOn;
} MenuSettings;
#include "appTypes.h"
void InitMenuSettings(MenuSettings *s)
{
@@ -65,4 +56,3 @@ void ClenupMenuSettings(MenuSettings *s){
}
#endif // APPMENUSETTINGS_H
@@ -1,14 +1,4 @@
#ifndef ANIMATION_H
#define ANIMATION_H
typedef struct {
int state;
int currentFrame;
int maxFrame;
int framesCounter;
int framesSpeed;
float animTimer;
} Animation;
#include "engine.h"
void UpdateAnimation(Animation *animation, float deltaTime) {
animation->animTimer += deltaTime;
@@ -25,5 +15,3 @@ void UpdateAnimation(Animation *animation, float deltaTime) {
animation->currentFrame = 0;
}
}
#endif // ANIMATION_H
+11 -15
View File
@@ -1,13 +1,7 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "engine.h"
typedef struct {
void** elements;
unsigned int count;
unsigned int capacity;
} Array;
Array* CreateArray(unsigned int initCapacity){
Array* CreateArray(unsigned int initCapacity)
{
Array* array = malloc(sizeof(Array));
if (!array) return NULL;
@@ -22,7 +16,8 @@ Array* CreateArray(unsigned int initCapacity){
return array;
}
int AddElementToArray(Array* array, void* element){
int AddElementToArray(Array* array, void* element)
{
if(array->count >= array->capacity) {
unsigned int newCapacity = array->capacity * 2;
void** newElements = realloc(array->elements, sizeof(void*) * newCapacity);
@@ -48,7 +43,8 @@ int AddElementToArray(Array* array, void* element){
// }
// SWAP AND POP REMOVE
int RemoveElementFromArray(Array* array, unsigned int index) {
int RemoveElementFromArray(Array* array, unsigned int index)
{
if (index >= array->count) return 0;
array->elements[index] = array->elements[array->count - 1];
@@ -58,7 +54,8 @@ int RemoveElementFromArray(Array* array, unsigned int index) {
return 1;
}
void* GetRandomElementFromArray(Array* array){
void* GetRandomElementFromArray(Array* array)
{
if (array == NULL || array->elements == NULL || array->count == 0) {
return NULL;
}
@@ -82,7 +79,8 @@ void RenderArray(Array* array, void (*renderFunc)(void*))
}
}
void FreeArray(Array** array) {
void FreeArray(Array** array)
{
if (!array || !*array) return;
free((*array)->elements);
@@ -92,5 +90,3 @@ void FreeArray(Array** array) {
*array = NULL;
}
#endif // ARRAY_H
@@ -1,8 +1,4 @@
#ifndef CAMERA_H
#define CAMERA_H
#include "input.h"
#include <raymath.h>
#include "engine.h"
Camera2D CreateCamera(Vector2 playerPosition, float initZoom){
int windowWidth = GetScreenWidth();
@@ -29,5 +25,3 @@ void UpdateCamera2D(Camera2D* camera, Vector2* position, Mouse* mouse){
UpdateCameraZoom(camera, &mouse->scaleFactor, &mouse->minZoom, &mouse->maxZoom);
}
#endif // CAMERA_H
@@ -1,16 +1,7 @@
#ifndef CONFIG_H
#define CONFIG_H
#define RINI_IMPLEMENTATION
#define RINI_VALUE_DELIMITER '='
#include <rini.h>
#include <stdio.h>
typedef struct {
char *path;
rini_config rini;
} Config;
#include "engine.h"
void InitConfig(Config *config, const char* path) {
config->rini = rini_load_config(path);
@@ -63,4 +54,3 @@ void CleanUpConfig(Config *config) {
rini_unload_config(&config->rini);
}
#endif // CONFIG_H
+1 -3
View File
@@ -1,5 +1,4 @@
#ifndef FONT_H
#define FONT_H
#include "engine.h"
void InitFont(Font *font, const char* path){
*font = LoadFont(path);
@@ -10,4 +9,3 @@ void CleanupFont(Font *font){
UnloadFont(*font);
}
#endif //FONT_H
@@ -1,29 +1,4 @@
#ifndef GAMEGUI_H
#define GAMEGUI_H
#include "sprite.h"
#include <raylib.h>
typedef enum {
NOT_CLICKED,
HOVER,
CLICKED
} ButtonState;
typedef struct
{
Sprite sprite;
Vector2 notClicked;
Vector2 hover;
Vector2 clicked;
bool isHovered;
bool isClicked;
} ImageButton;
typedef struct
{
Sprite sprite;
} ImageElement;
#include "engine.h"
ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Vector2 *hover, Rectangle *destRec){
return (ImageButton){
@@ -95,5 +70,3 @@ void renderImageElement(ImageElement *e){
RenderSprite(&e->sprite);
}
#endif // GAMEGUI_H
+1 -10
View File
@@ -1,14 +1,6 @@
#ifndef GUI_H
#define GUI_H
#define RAYGUI_IMPLEMENTATION
#include <raygui.h>
typedef struct
{
Rectangle rec;
char *text;
} Button;
#include "engine.h"
Button initButton(char *text, Vector2 dimensions, Vector2 position)
{
@@ -29,4 +21,3 @@ void renderButton(Button *b)
GuiButton(b->rec, b->text);
}
#endif // GUI_H
+1 -19
View File
@@ -1,20 +1,4 @@
#ifndef INPUT_H
#define INPUT_H
#include <raymath.h>
typedef struct {
Vector2 screenPosition;
Vector2 worldPosition;
float zoomSpeed;
float minZoom;
float maxZoom;
float scaleFactor;
float wheelMove;
bool leftButton;
bool rightButton;
Texture2D cursorTexture;
} Mouse;
#include "engine.h"
Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom, Texture2D *texture){
HideCursor();
@@ -57,5 +41,3 @@ Vector2 GetDirectionVector(void){
if (Vector2Length(vector) > 0.0f) {vector = Vector2Normalize(vector); }
return vector;
}
#endif //INPUT_H
@@ -1,19 +1,4 @@
#ifndef OBJECT_H
#define OBJECT_H
#include "sprite.h"
#include "vector.h"
typedef struct {
Sprite sprite;
Vector2 position;
} Object;
typedef struct {
Object *data;
const Object *prototype;
size_t count;
} ObjectArray;
#include "engine.h"
ObjectArray CreateObjectArray(const Object *prototype, const size_t count) {
ObjectArray objects = {0};
@@ -126,4 +111,3 @@ void RenderObjectArray(const ObjectArray *objects){
}
}
#endif // OBJECT_H
@@ -1,15 +1,4 @@
#ifndef PHYSICS_H
#define PHYSICS_H
#include <raymath.h>
typedef struct
{
Vector2 position;
Vector2 direction;
Vector2 velocity;
float speed;
} Physics;
#include "engine.h"
void UpdatePhysicsDirection(Vector2 *direction, Vector2 vector)
{
@@ -38,4 +27,3 @@ void UpdatePhysics(Physics *physics, Vector2 direction)
UpdatePhysicsPosition(&physics->position, &physics->velocity);
}
#endif // PHYSICS_H
@@ -1,12 +1,4 @@
#ifndef POSTFX_H
#define POSTFX_H
typedef struct {
Shader shader;
int resolutionLoc;
int strengthLoc;
float strength;
} PostProcessing;
#include "engine.h"
PostProcessing CreatePostFX(const char* shaderPath){
PostProcessing postFX = {0};
@@ -42,5 +34,3 @@ void UnloadPostFX(PostProcessing *postFX){
if (postFX->shader.id == 0) return;
UnloadShader(postFX->shader);
}
#endif // POSTFX_H
@@ -1,11 +1,4 @@
#ifndef SOUNDTRACK_H
#define SOUNDTRACK_H
typedef struct {
Music music;
bool playing;
bool paused;
} Soundtrack;
#include "engine.h"
Soundtrack LoadSoundtrack(const char* musicPath){
Soundtrack soundtrack = {
@@ -35,5 +28,3 @@ void UpdateSoundtrack(Soundtrack *soundtrack, bool playing){
}
#endif // SOUNDTRACK_H
@@ -1,18 +1,5 @@
#ifndef SPRITE_H
#define SPRITE_H
#include "engine.h"
#include <raymath.h>
typedef struct
{
Texture2D texture;
Rectangle sourceRec;
Rectangle destRec;
Vector2 frameSize;
Vector2 origin;
float rotation;
Color color;
} Sprite;
void UpdateSpriteSourceRec(Sprite *sprite, const Vector2 *vector)
{
@@ -58,5 +45,3 @@ void PrintSprite(const Sprite *sprite)
printf(" Sprite.rotation: %f\n", sprite->rotation);
printf(" Sprite.color: r = %d, g = %d, b = %d, a = %d\n", sprite->color.r, sprite->color.g, sprite->color.b, sprite->color.a);
}
#endif // SPRITE_H
@@ -1,10 +1,4 @@
#ifndef VECTOR_H
#define VECTOR_H
typedef struct {
Vector2 *data;
size_t count;
} Vector2Array;
#include "engine.h"
bool IsVectorZero(Vector2 v) {
float epsilon = 0.01f;
@@ -18,4 +12,3 @@ Vector2 GetRandomVector(const Rectangle bounds) {
};
}
#endif // VECTOR_H
+1 -2
View File
@@ -1,5 +1,4 @@
#include <raylib.h>
#include "app.h"
#include "appTypes.h"
int main(void)
{