final oop style

This commit is contained in:
huaqo
2026-03-01 12:57:09 +01:00
parent c064e80be2
commit e1596f633d
10 changed files with 1004 additions and 393 deletions
-2
View File
@@ -20,11 +20,9 @@ C_FLAGS = \
INCLUDE_FLAGS = -Iinclude INCLUDE_FLAGS = -Iinclude
EXTERNAL_ENGINE = -Iexternal/engine
EXTERNAL_RAYGUI = -Iexternal/raygui EXTERNAL_RAYGUI = -Iexternal/raygui
EXTERNAL_RINI = -Iexternal/rini EXTERNAL_RINI = -Iexternal/rini
EXTERNAL_FLAGS = \ EXTERNAL_FLAGS = \
$(EXTERNAL_ENGINE) \
$(EXTERNAL_RINI) \ $(EXTERNAL_RINI) \
$(EXTERNAL_RAYGUI) $(EXTERNAL_RAYGUI)
+684
View File
@@ -0,0 +1,684 @@
[
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/app.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/app.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appGameBirds.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appGameBirds.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appGame.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appGame.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appGameEnemies.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appGameEnemies.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appGameFloor.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appGameFloor.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appGameIslands.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appGameIslands.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appGamePlayer.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appGamePlayer.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appGameShip.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appGameShip.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appGameShoot.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appGameShoot.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appLogo.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appLogo.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appMenu.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appMenu.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appMenuMainBackground.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appMenuMainBackground.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appMenuMain.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appMenuMain.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appMenuSettings.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appMenuSettings.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/appState.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/appState.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineAnimation.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineAnimation.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineArray.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineArray.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineCamera.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineCamera.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineConfig.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineConfig.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineFont.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineFont.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineGamegui.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineGamegui.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineGui.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineGui.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineInput.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineInput.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineObject.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineObject.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/enginePhysics.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/enginePhysics.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/enginePostfx.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/enginePostfx.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineRectangle.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineRectangle.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineSoundtrack.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineSoundtrack.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineSprite.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineSprite.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/engineVector.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/engineVector.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
},
{
"arguments": [
"/usr/bin/gcc",
"-c",
"-std=c99",
"-g",
"-Wall",
"-Wpedantic",
"-Wshadow",
"-Wstrict-prototypes",
"-Wno-unknown-pragmas",
"-Iinclude",
"-Iexternal/rini",
"-Iexternal/raygui",
"-o",
"bin/osx/game",
"src/main.c"
],
"directory": "/home/huaqo/dev/the-last-hive",
"file": "/home/huaqo/dev/the-last-hive/src/main.c",
"output": "/home/huaqo/dev/the-last-hive/bin/osx/game"
}
]
+8
View File
@@ -0,0 +1,8 @@
# ship_start
start_id = 0
start_path = assets/ship_start.png
start_frameSize = 16
start_spped_0 = 0
start_speed_1 = 5
start_speed_2 = 10
start_rotationSpeed = 50
+153 -205
View File
@@ -1,271 +1,215 @@
#ifndef APPTYPES_H #ifndef APPTYPES_H
#define APPTYPES_H #define APPTYPES_H
//INCLUDES// // INCLUDES//
#include <raylib.h>
#include <engine.h> #include <engine.h>
#include <raylib.h>
//DEFINES// // DEFINES//
#define TEXT_COLOR_DARK (Color){ 182, 137, 98, 255} #define TEXT_COLOR_DARK (Color){182, 137, 98, 255}
#define TEXT_COLOR_LIGHT (Color){ 243, 229, 194, 255} #define TEXT_COLOR_LIGHT (Color){243, 229, 194, 255}
//ENUMS// // ENUMS//
typedef enum typedef enum {
{ MENU_CURSOR_TEX,
MENU_CURSOR_TEX, MENU_BIG_BUTTONS_TEX,
MENU_BIG_BUTTONS_TEX, MENU_BOARD_TEX,
MENU_BOARD_TEX, MENU_CLOUD_BACKGROUND,
MENU_CLOUD_BACKGROUND, MENU_CLOUD_MIDGROUND,
MENU_CLOUD_MIDGROUND, MENU_CLOUD_FOREGROUND,
MENU_CLOUD_FOREGROUND, MENU_TEX_COUNT
MENU_TEX_COUNT
} MenuTextureID; } MenuTextureID;
typedef enum typedef enum { MENU_MUSIC, MENU_SOUNDTRACK_COUNT } MenuSoundtrackID;
{
MENU_MUSIC,
MENU_SOUNDTRACK_COUNT
} MenuSoundtrackID;
typedef enum typedef enum { HOVER_SOUND, CLICK_SOUND, MENU_SOUND_COUNT } MenuSoundID;
{
HOVER_SOUND,
CLICK_SOUND,
MENU_SOUND_COUNT
} MenuSoundID;
typedef enum MenuView { typedef enum MenuView { MAIN = 0, SETTINGS = 1 } MenuView;
MAIN = 0,
SETTINGS = 1
} MenuView;
typedef enum typedef enum { START_SHIP, PLAYER_TEX_COUNT } playerTextureID;
{
START_SHIP,
PLAYER_TEX_COUNT
} playerTextureID;
typedef enum { typedef enum { ANCHOR, SLOW_AHEAD, FAST_AHEAD, SPEED_COUNT } playerSpeedID;
ANCHOR,
SLOW_AHEAD,
FAST_AHEAD,
SPEED_COUNT
} playerSpeedID;
typedef enum { ISLAND, ISLANDS_TEX_COUNT } islandsTextureID;
typedef enum typedef enum { POST_FX, SHADER_COUNT } ShaderID;
{
ISLAND,
ISLANDS_TEX_COUNT
} islandsTextureID;
typedef enum typedef enum { BEE_AMBIENT, SOUNDTRACK_COUNT } SoundtrackID;
{
POST_FX,
SHADER_COUNT
} ShaderID;
typedef enum typedef enum View { LOGO = 0, MENU = 1, GAMEPLAY = 2 } View;
{
BEE_AMBIENT,
SOUNDTRACK_COUNT
} SoundtrackID;
typedef enum View { // STRUCTS//
LOGO = 0,
MENU = 1,
GAMEPLAY = 2
} View;
//STRUCTS//
typedef struct { typedef struct {
int frameCounter; int frameCounter;
int positionX; int positionX;
int positionY; int positionY;
int lettersCount; int lettersCount;
int topSideRecWidth; int topSideRecWidth;
int leftSideRecHeight; int leftSideRecHeight;
int bottomSideRecWidth; int bottomSideRecWidth;
int rightSideRecHeight; int rightSideRecHeight;
int state; int state;
float alpha; float alpha;
} LogoState; } LogoState;
typedef struct { typedef struct {
Sprite sprite; Sprite sprite;
float scrolling; float scrolling;
float scale; float scale;
float scrollSpeed; float scrollSpeed;
Vector2 pos; Vector2 pos;
} Background; } Background;
typedef struct { typedef struct {
Assets assets; Assets assets;
Mouse mouse; Mouse mouse;
Texture2D textures[MENU_TEX_COUNT]; Texture2D textures[MENU_TEX_COUNT];
Sound sounds[MENU_SOUND_COUNT]; Sound sounds[MENU_SOUND_COUNT];
Soundtrack soundtracks[MENU_SOUNDTRACK_COUNT]; Soundtrack soundtracks[MENU_SOUNDTRACK_COUNT];
ImageElement board; ImageElement board;
ImageButton playButton; ImageButton playButton;
ImageButton quitButton; ImageButton quitButton;
ImageButton settingsButton; ImageButton settingsButton;
int menuScale; int menuScale;
Background background; Background background;
Background midground; Background midground;
Background foreground; Background foreground;
} MenuMain; } MenuMain;
typedef struct typedef struct {
{ Button showFPS;
Button showFPS; Button limitFPS;
Button limitFPS; Button soundtrackOn;
Button soundtrackOn;
} MenuSettings; } MenuSettings;
typedef struct {
typedef struct MenuView menuView;
{ MenuMain menuMain;
MenuView menuView; MenuSettings menuSettings;
MenuMain menuMain;
MenuSettings menuSettings;
} MenuState; } MenuState;
typedef struct {
typedef struct Sprite sprite;
{ Rectangle bounds;
Sprite sprite; Shader shader;
Rectangle bounds; float time;
Shader shader;
float time;
} Floor; } Floor;
typedef struct typedef struct {
{ Sprite sprite;
Sprite sprite; Animation animation;
Animation animation; Physics physics;
Physics physics; float rotation;
float rotation;
} Player; } Player;
typedef enum typedef enum { BOAT, ENEMIES_TEX_COUNT } enemiesTextureID;
{
BOAT,
ENEMIES_TEX_COUNT
} enemiesTextureID;
typedef enum typedef enum { START, SHIP_COUNT } shipID;
{
START,
SHIP_COUNT
} shipID;
typedef struct typedef struct {
{ int id;
int id; char *assetPath;
char* assetPath; int frameSize;
int frameSize; int speed0;
int speed0; int speed1;
int speed1; int speed2;
int speed2; int rotationSpeed;
int rotationSpeed; } Ship;
}Ship;
#define MAX_ENEMIES 100 #define MAX_ENEMIES 100
typedef struct typedef struct {
{ Config config;
Config config; int count;
int count; Sprite sprite[MAX_ENEMIES];
Sprite sprite[MAX_ENEMIES]; Animation animation[MAX_ENEMIES];
Animation animation[MAX_ENEMIES]; Physics physics[MAX_ENEMIES];
Physics physics[MAX_ENEMIES]; bool arrived[MAX_ENEMIES];
bool arrived[MAX_ENEMIES]; Vector2 destPos[MAX_ENEMIES];
Vector2 destPos[MAX_ENEMIES];
} Enemies; } Enemies;
typedef enum typedef enum { FLYING, BIRDS_TEX_COUNT } birdsTextureID;
{
FLYING,
BIRDS_TEX_COUNT
} birdsTextureID;
#define MAX_BIRDS 100 #define MAX_BIRDS 100
typedef struct { typedef struct {
int count; int count;
Sprite sprite[MAX_BIRDS]; Sprite sprite[MAX_BIRDS];
Animation animation[MAX_BIRDS]; Animation animation[MAX_BIRDS];
Physics physics[MAX_BIRDS]; Physics physics[MAX_BIRDS];
bool arrived[MAX_BIRDS]; bool arrived[MAX_BIRDS];
Vector2 destPos[MAX_BIRDS]; Vector2 destPos[MAX_BIRDS];
} Birds; } Birds;
typedef struct { typedef struct {
Sprite sprite; Sprite sprite;
Animation animation; Animation animation;
Physics physics; Physics physics;
} Islands; } Islands;
typedef struct
{
Assets assets;
PostProcessing postFX[SHADER_COUNT];
Soundtrack soundtracks[SOUNDTRACK_COUNT];
RenderTexture2D target;
Floor floor;
Birds birds;
Enemies enemies;
Islands islands;
Mouse mouse;
Image image;
} GameState;
typedef struct {
View currentView;
bool running;
bool gameStarted;
} State;
typedef struct {
bool showFPS;
bool limitFPS;
bool soundtrackOn;
} Flags;
typedef struct {
Config config;
State state;
Flags flags;
Window window;
Font font;
LogoState logo;
MenuState menu;
GameState game;
} App;
#define MAX_PROJECTILES 10 #define MAX_PROJECTILES 10
typedef struct { typedef struct {
Physics physics[MAX_PROJECTILES]; Physics physics[MAX_PROJECTILES];
bool active[MAX_PROJECTILES]; bool active[MAX_PROJECTILES];
float radius[MAX_PROJECTILES]; float radius[MAX_PROJECTILES];
} Projectile; } Projectiles;
//FUNCTIONS// typedef struct {
Assets assets;
PostProcessing postFX[SHADER_COUNT];
Soundtrack soundtracks[SOUNDTRACK_COUNT];
RenderTexture2D target;
Floor floor;
Birds birds;
Enemies enemies;
Islands islands;
Mouse mouse;
Image image;
Projectiles projectiles;
} GameState;
typedef struct {
View currentView;
bool running;
bool gameStarted;
} State;
typedef struct {
bool showFPS;
bool limitFPS;
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 InitLogo(LogoState *l);
void UpdateLogo(LogoState *l, View *currentView, bool *running); void UpdateLogo(LogoState *l, View *currentView, bool *running);
void RenderLogo(const LogoState *l, Flags *flags); void RenderLogo(const LogoState *l, Flags *flags);
void InitBackground(float scrollSpeed, Background *bg, Texture2D *texture, const TextureAsset *backgroundAsset); void InitBackground(float scrollSpeed, Background *bg, Texture2D *texture,
const TextureAsset *backgroundAsset);
void UpdateBackground(Background *bg); void UpdateBackground(Background *bg);
void RenderBackground(Background *bg); void RenderBackground(Background *bg);
void InitMenuMain(MenuMain *m); void InitMenuMain(MenuMain *m);
void UpdateMenuMain(MenuMain *m, State *state, Flags *flags, MenuView *menuView); void UpdateMenuMain(MenuMain *m, State *state, Flags *flags,
MenuView *menuView);
void RenderMenuMain(MenuMain *m, Font *font, const char *title, Flags *flags); void RenderMenuMain(MenuMain *m, Font *font, const char *title, Flags *flags);
void CleanupMenuMain(MenuMain *m); void CleanupMenuMain(MenuMain *m);
void InitMenuSettings(MenuSettings *s); void InitMenuSettings(MenuSettings *s);
void UpdateMenuSettings(MenuSettings *s, MenuView *menuView, State *state, Flags *flags); void UpdateMenuSettings(MenuSettings *s, MenuView *menuView, State *state,
Flags *flags);
void RenderMenuSettings(MenuSettings *s, Flags *flags); void RenderMenuSettings(MenuSettings *s, Flags *flags);
void CleanupMenuSettings(MenuSettings *s); void CleanupMenuSettings(MenuSettings *s);
@@ -280,7 +224,7 @@ void RenderFloor(Floor *floor);
void UnloadFloor(Floor *floor); void UnloadFloor(Floor *floor);
playerSpeedID GetPlayerSpeedID(float speed); playerSpeedID GetPlayerSpeedID(float speed);
Player* GetPlayer(void); Player *GetPlayer(void);
void CreatePlayer(void); void CreatePlayer(void);
void UpdatePlayer(void); void UpdatePlayer(void);
void RenderPlayer(void); void RenderPlayer(void);
@@ -297,6 +241,10 @@ Islands CreateIslands(void);
void UpdateIslands(Islands *islands); void UpdateIslands(Islands *islands);
void RenderIslands(Islands *islands); void RenderIslands(Islands *islands);
Projectiles CreateProjectiles(void);
void UpdateProjectiles(Projectiles *projectiles);
void RenderProjectiles(Projectiles *projectiles);
void InitGame(App *app); void InitGame(App *app);
void UpdateGame(App *app); void UpdateGame(App *app);
void RenderComponents(App *app); void RenderComponents(App *app);
@@ -311,4 +259,4 @@ void InitApp(App *app);
void UpdateApp(App *app); void UpdateApp(App *app);
void CleanupApp(App *app); void CleanupApp(App *app);
#endif //APPTYPES_H #endif // APPTYPES_H
+39 -44
View File
@@ -1,56 +1,51 @@
#include "app.h" #include "app.h"
void ConfigApp(App* app){ void ConfigApp(App *app) {
InitConfig(&app->config, "config/config.ini"); InitConfig(&app->config, "config/config.ini");
app->state.currentView = GetConfigInt(&app->config, "startView"); app->state.currentView = GetConfigInt(&app->config, "startView");
app->flags.showFPS = GetConfigInt(&app->config, "showFPS"); app->flags.showFPS = GetConfigInt(&app->config, "showFPS");
app->flags.limitFPS = GetConfigInt(&app->config, "limitFPS"); app->flags.limitFPS = GetConfigInt(&app->config, "limitFPS");
app->flags.soundtrackOn = GetConfigInt(&app->config, "soundtrackOn"); app->flags.soundtrackOn = GetConfigInt(&app->config, "soundtrackOn");
app->window.title = GetConfigString(&app->config, "windowTitle"); app->window.title = GetConfigString(&app->config, "windowTitle");
app->window.width = GetConfigInt(&app->config, "windowWidth"); app->window.width = GetConfigInt(&app->config, "windowWidth");
app->window.height = GetConfigInt(&app->config, "windowHeight"); app->window.height = GetConfigInt(&app->config, "windowHeight");
} }
void InitApp(App *app){ void InitApp(App *app) {
InitFont(&app->font, GetConfigString(&app->config, "fontPath")); InitFont(&app->font, GetConfigString(&app->config, "fontPath"));
InitLogo(&app->logo); InitLogo(&app->logo);
InitMenu(&app->menu); InitMenu(&app->menu);
InitGame(app); InitGame(app);
} }
void UpdateApp(App *app){ void UpdateApp(App *app) {
app->state.running = true; app->state.running = true;
app->state.gameStarted = false; app->state.gameStarted = false;
while (app->state.running) while (app->state.running) {
{ switch (app->state.currentView) {
switch (app->state.currentView) case LOGO: {
{ UpdateLogo(&app->logo, &app->state.currentView, &app->state.running);
case LOGO: RenderLogo(&app->logo, &app->flags);
{ } break;
UpdateLogo(&app->logo, &app->state.currentView, &app->state.running); case MENU: {
RenderLogo(&app->logo, &app->flags); UpdateMenu(&app->menu, &app->state, &app->flags);
}break; RenderMenu(&app->menu, &app->font, app->window.title, &app->flags);
case MENU: } break;
{ case GAMEPLAY: {
UpdateMenu(&app->menu, &app->state, &app->flags); UpdateGame(app);
RenderMenu(&app->menu, &app->font, app->window.title, &app->flags); RenderGame(app);
}break; } break;
case GAMEPLAY: default:
{ break;
UpdateGame(app);
RenderGame(app);
}break;
default: break;
}
} }
}
} }
void CleanupApp(App *app){ void CleanupApp(App *app) {
CleanupMenu(&app->menu); CleanupMenu(&app->menu);
CleanupGame(app); CleanupGame(app);
CleanupFont(&app->font); CleanupFont(&app->font);
CleanUpConfig(&app->config); CleanUpConfig(&app->config);
} }
+79 -104
View File
@@ -1,145 +1,120 @@
#include "app.h" #include "app.h"
const ShaderAsset shaderAssets[SHADER_COUNT] = { const ShaderAsset shaderAssets[SHADER_COUNT] = {{"shaders/postfx.fs"}};
{"shaders/postfx.fs"}
};
const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = { const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = {{"assets/sea.mp3"}};
{"assets/sea.mp3"}
};
void InitGame(App *app) {
void InitGame(App *app)
{
SetRandomSeed(1234); SetRandomSeed(1234);
GameState *g = &app->game; GameState *g = &app->game;
g->assets = (Assets){ g->assets = (Assets){.shaderAssets = shaderAssets,
.shaderAssets = shaderAssets, .soundtrackAssets = soundtrackAssets};
.soundtrackAssets = soundtrackAssets
};
for (int i = 0; i < SHADER_COUNT; i++) for (int i = 0; i < SHADER_COUNT; i++) {
{ g->postFX[i] = CreatePostFX(g->assets.shaderAssets[i].path);
g->postFX[i] = CreatePostFX(g->assets.shaderAssets[i].path);
} }
for (int i = 0; i < SOUNDTRACK_COUNT; i++) for (int i = 0; i < SOUNDTRACK_COUNT; i++) {
{ g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
} }
g->target = LoadRenderTexture(app->window.width, app->window.height); g->target = LoadRenderTexture(app->window.width, app->window.height);
CreatePlayer(); CreatePlayer();
Player* player = GetPlayer(); Player *player = GetPlayer();
CreateCamera(player->physics.position, 10.0f); CreateCamera(player->physics.position, 10.0f);
g->birds = CreateBirds(); g->birds = CreateBirds();
g->enemies = CreateEnemies(); g->enemies = CreateEnemies();
g->islands = CreateIslands(); g->islands = CreateIslands();
g->floor = CreateFloor(); g->floor = CreateFloor();
g->projectiles = CreateProjectiles();
Texture2D mouseTexture = LoadTexture("assets/mouse.png"); Texture2D mouseTexture = LoadTexture("assets/mouse.png");
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &mouseTexture); g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &mouseTexture);
} }
void StartGame(App *app) void StartGame(App *app) {
{ if (!app->state.gameStarted) {
if(!app->state.gameStarted){ app->state.gameStarted = true;
app->state.gameStarted = true; }
}
} }
void UpdateGame(App *app) {
GameState *g = &app->game;
if (app->flags.limitFPS) {
SetTargetFPS(60);
} else {
SetTargetFPS(0);
}
void UpdateGame(App *app) StartGame(app);
{
GameState *g = &app->game;
if (app->flags.limitFPS){
SetTargetFPS(60);
} else {
SetTargetFPS(0);
}
StartGame(app); OnEscapeChangeView(app, MENU);
OnWindowClosedStoppApp(app);
OnEscapeChangeView(app, MENU); for (int i = 0; i < SHADER_COUNT; i++) {
OnWindowClosedStoppApp(app); UpdatePostFX(&g->postFX[i]);
}
for (int i = 0; i < SOUNDTRACK_COUNT; i++) {
UpdateSoundtrack(&g->soundtracks[i], app->flags.soundtrackOn);
}
for (int i = 0; i < SHADER_COUNT; i++) UpdateMouse(&g->mouse);
{ Player *player = GetPlayer();
UpdatePostFX(&g->postFX[i]); UpdateCamera2D(&player->physics.position, &g->mouse);
} UpdateFloor(&g->floor);
for (int i = 0; i < SOUNDTRACK_COUNT; i++) UpdatePlayer();
{ UpdateBirds(&g->birds);
UpdateSoundtrack(&g->soundtracks[i], app->flags.soundtrackOn); UpdateEnemies(&g->enemies);
} UpdateIslands(&g->islands);
UpdateMouse(&g->mouse);
Player* player = GetPlayer();
UpdateCamera2D(&player->physics.position, &g->mouse);
UpdateFloor(&g->floor);
UpdatePlayer();
UpdateBirds(&g->birds);
UpdateEnemies(&g->enemies);
UpdateIslands(&g->islands);
} }
void RenderComponents(App *app) void RenderComponents(App *app) {
{ GameState *g = &app->game;
GameState *g = &app->game; RenderFloor(&g->floor);
RenderFloor(&g->floor); RenderPlayer();
RenderPlayer(); RenderEnemies(&g->enemies);
RenderEnemies(&g->enemies); RenderBirds(&g->birds);
RenderBirds(&g->birds); RenderIslands(&g->islands);
RenderIslands(&g->islands);
} }
void RenderGame(App *app) void RenderGame(App *app) {
{ GameState *g = &app->game;
GameState *g = &app->game;
BeginTextureMode(g->target);
ClearBackground(BLACK);
Camera2D *camera = GetCamera();
BeginMode2D(*camera);
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
);
EndTextureMode();
BeginDrawing(); BeginTextureMode(g->target);
ClearBackground(BLACK); ClearBackground(BLACK);
for (int i = 0; i < SHADER_COUNT; i++) Camera2D *camera = GetCamera();
{ BeginMode2D(*camera);
RenderPostFX(&g->postFX[i], &g->target); 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);
EndTextureMode();
if (app->flags.showFPS) BeginDrawing();
{ ClearBackground(BLACK);
DrawFPS(10, 10); for (int i = 0; i < SHADER_COUNT; i++) {
} RenderPostFX(&g->postFX[i], &g->target);
}
EndDrawing(); if (app->flags.showFPS) {
DrawFPS(10, 10);
}
EndDrawing();
} }
void CleanupGame(App *app) void CleanupGame(App *app) {
{ GameState *g = &app->game;
GameState *g = &app->game; for (int i = 0; i < SHADER_COUNT; i++) {
for (int i = 0; i < SHADER_COUNT; i++) UnloadPostFX(&g->postFX[i]);
{ }
UnloadPostFX(&g->postFX[i]); for (int i = 0; i < SOUNDTRACK_COUNT; i++) {
} UnloadMusicStream(g->soundtracks[i].music);
for (int i = 0; i < SOUNDTRACK_COUNT; i++) }
{ UnloadRenderTexture(g->target);
UnloadMusicStream(g->soundtracks[i].music);
}
UnloadRenderTexture(g->target);
} }
+27 -35
View File
@@ -1,47 +1,39 @@
#include "app.h" #include "app.h"
const TextureAsset islandsTextureAssets[ISLANDS_TEX_COUNT] = { const TextureAsset islandsTextureAssets[ISLANDS_TEX_COUNT] = {
{"assets/island.png", 16.0f, 16.0f, 0.0f} {"assets/island.png", 16.0f, 16.0f, 0.0f}};
};
Islands CreateIslands(void){ Islands CreateIslands(void) {
TextureAsset islandAsset = islandsTextureAssets[ISLAND]; TextureAsset islandAsset = islandsTextureAssets[ISLAND];
Texture2D texture = LoadTexture(islandAsset.path); Texture2D texture = LoadTexture(islandAsset.path);
float frameWidth = islandAsset.frameWidth; float frameWidth = islandAsset.frameWidth;
float rotation = islandAsset.rotation; float rotation = islandAsset.rotation;
Sprite islandSprite = {
.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
};
Physics islandPhysics = { Sprite islandSprite = {
.position = (Vector2){-100.0f, 0.0f}, .texture = texture,
.direction = (Vector2){0.0f, 0.0f}, .frameSize = {frameWidth, frameWidth},
.speed = 10.0f .sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
}; .destRec = {GetScreenWidth() / 2, 0.0f, frameWidth, frameWidth},
.origin = {frameWidth / 2, frameWidth / 2},
.rotation = rotation,
.color = WHITE};
return (Islands){ Physics islandPhysics = {.position = (Vector2){-100.0f, 0.0f},
.sprite = islandSprite, .direction = (Vector2){0.0f, 0.0f},
.physics = islandPhysics .speed = 10.0f};
};
return (Islands){.sprite = islandSprite, .physics = islandPhysics};
} }
void UpdateIslands(Islands *islands){ void UpdateIslands(Islands *islands) {
UpdatePhysics(&islands->physics, (Vector2){0.0f,0.0f}); UpdatePhysics(&islands->physics, (Vector2){0.0f, 0.0f});
UpdateSpriteDestRec(&islands->sprite, &islands->physics.position); UpdateSpriteDestRec(&islands->sprite, &islands->physics.position);
UpdateAnimation(&islands->animation, GetFrameTime()); UpdateAnimation(&islands->animation, GetFrameTime());
UpdateSpriteSourceRec(&islands->sprite, &(Vector2){islands->sprite.frameSize.x * islands->animation.currentFrame, islands->sprite.frameSize.y}); UpdateSpriteSourceRec(
} &islands->sprite,
&(Vector2){islands->sprite.frameSize.x * islands->animation.currentFrame,
void RenderIslands(Islands *islands){ islands->sprite.frameSize.y});
RenderSprite(&islands->sprite);
} }
void RenderIslands(Islands *islands) { RenderSprite(&islands->sprite); }
+7
View File
@@ -0,0 +1,7 @@
#include "app.h"
Projectiles CreateProjectiles(void) {}
void UpdateProjectiles(Projectiles *projectiles) {}
void RenderProjectiles(Projectiles *projectiles) {}
+7
View File
@@ -0,0 +1,7 @@
#include "app.h"
Ship InitShip(int shipID) {
Config config;
InitConfig(&config, "config/ships.ini");
Ship ship;
}
-3
View File
@@ -1,3 +0,0 @@
#include "app.h"