final oop style
This commit is contained in:
@@ -1,56 +1,51 @@
|
||||
#include "app.h"
|
||||
|
||||
void ConfigApp(App* app){
|
||||
InitConfig(&app->config, "config/config.ini");
|
||||
app->state.currentView = GetConfigInt(&app->config, "startView");
|
||||
app->flags.showFPS = GetConfigInt(&app->config, "showFPS");
|
||||
app->flags.limitFPS = GetConfigInt(&app->config, "limitFPS");
|
||||
app->flags.soundtrackOn = GetConfigInt(&app->config, "soundtrackOn");
|
||||
app->window.title = GetConfigString(&app->config, "windowTitle");
|
||||
app->window.width = GetConfigInt(&app->config, "windowWidth");
|
||||
app->window.height = GetConfigInt(&app->config, "windowHeight");
|
||||
void ConfigApp(App *app) {
|
||||
InitConfig(&app->config, "config/config.ini");
|
||||
app->state.currentView = GetConfigInt(&app->config, "startView");
|
||||
app->flags.showFPS = GetConfigInt(&app->config, "showFPS");
|
||||
app->flags.limitFPS = GetConfigInt(&app->config, "limitFPS");
|
||||
app->flags.soundtrackOn = GetConfigInt(&app->config, "soundtrackOn");
|
||||
app->window.title = GetConfigString(&app->config, "windowTitle");
|
||||
app->window.width = GetConfigInt(&app->config, "windowWidth");
|
||||
app->window.height = GetConfigInt(&app->config, "windowHeight");
|
||||
}
|
||||
|
||||
void InitApp(App *app){
|
||||
InitFont(&app->font, GetConfigString(&app->config, "fontPath"));
|
||||
InitLogo(&app->logo);
|
||||
InitMenu(&app->menu);
|
||||
InitGame(app);
|
||||
void InitApp(App *app) {
|
||||
InitFont(&app->font, GetConfigString(&app->config, "fontPath"));
|
||||
InitLogo(&app->logo);
|
||||
InitMenu(&app->menu);
|
||||
InitGame(app);
|
||||
}
|
||||
|
||||
void UpdateApp(App *app){
|
||||
void UpdateApp(App *app) {
|
||||
|
||||
app->state.running = true;
|
||||
app->state.gameStarted = false;
|
||||
app->state.running = true;
|
||||
app->state.gameStarted = false;
|
||||
|
||||
while (app->state.running)
|
||||
{
|
||||
switch (app->state.currentView)
|
||||
{
|
||||
case LOGO:
|
||||
{
|
||||
UpdateLogo(&app->logo, &app->state.currentView, &app->state.running);
|
||||
RenderLogo(&app->logo, &app->flags);
|
||||
}break;
|
||||
case MENU:
|
||||
{
|
||||
UpdateMenu(&app->menu, &app->state, &app->flags);
|
||||
RenderMenu(&app->menu, &app->font, app->window.title, &app->flags);
|
||||
}break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
UpdateGame(app);
|
||||
RenderGame(app);
|
||||
}break;
|
||||
default: break;
|
||||
}
|
||||
while (app->state.running) {
|
||||
switch (app->state.currentView) {
|
||||
case LOGO: {
|
||||
UpdateLogo(&app->logo, &app->state.currentView, &app->state.running);
|
||||
RenderLogo(&app->logo, &app->flags);
|
||||
} break;
|
||||
case MENU: {
|
||||
UpdateMenu(&app->menu, &app->state, &app->flags);
|
||||
RenderMenu(&app->menu, &app->font, app->window.title, &app->flags);
|
||||
} break;
|
||||
case GAMEPLAY: {
|
||||
UpdateGame(app);
|
||||
RenderGame(app);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CleanupApp(App *app){
|
||||
CleanupMenu(&app->menu);
|
||||
CleanupGame(app);
|
||||
CleanupFont(&app->font);
|
||||
CleanUpConfig(&app->config);
|
||||
void CleanupApp(App *app) {
|
||||
CleanupMenu(&app->menu);
|
||||
CleanupGame(app);
|
||||
CleanupFont(&app->font);
|
||||
CleanUpConfig(&app->config);
|
||||
}
|
||||
|
||||
|
||||
+79
-104
@@ -1,145 +1,120 @@
|
||||
#include "app.h"
|
||||
|
||||
const ShaderAsset shaderAssets[SHADER_COUNT] = {
|
||||
{"shaders/postfx.fs"}
|
||||
};
|
||||
const ShaderAsset shaderAssets[SHADER_COUNT] = {{"shaders/postfx.fs"}};
|
||||
|
||||
const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = {
|
||||
{"assets/sea.mp3"}
|
||||
};
|
||||
const SoundtrackAsset soundtrackAssets[SOUNDTRACK_COUNT] = {{"assets/sea.mp3"}};
|
||||
|
||||
void InitGame(App *app) {
|
||||
|
||||
void InitGame(App *app)
|
||||
{
|
||||
|
||||
SetRandomSeed(1234);
|
||||
GameState *g = &app->game;
|
||||
g->assets = (Assets){
|
||||
.shaderAssets = shaderAssets,
|
||||
.soundtrackAssets = soundtrackAssets
|
||||
};
|
||||
g->assets = (Assets){.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 < SHADER_COUNT; i++) {
|
||||
g->postFX[i] = CreatePostFX(g->assets.shaderAssets[i].path);
|
||||
}
|
||||
|
||||
for (int i = 0; i < SOUNDTRACK_COUNT; i++)
|
||||
{
|
||||
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
|
||||
for (int i = 0; i < SOUNDTRACK_COUNT; i++) {
|
||||
g->soundtracks[i] = LoadSoundtrack(g->assets.soundtrackAssets[i].path);
|
||||
}
|
||||
|
||||
|
||||
g->target = LoadRenderTexture(app->window.width, app->window.height);
|
||||
|
||||
CreatePlayer();
|
||||
Player* player = GetPlayer();
|
||||
Player *player = GetPlayer();
|
||||
CreateCamera(player->physics.position, 10.0f);
|
||||
g->birds = CreateBirds();
|
||||
g->enemies = CreateEnemies();
|
||||
g->islands = CreateIslands();
|
||||
g->floor = CreateFloor();
|
||||
g->projectiles = CreateProjectiles();
|
||||
|
||||
Texture2D mouseTexture = LoadTexture("assets/mouse.png");
|
||||
g->mouse = CreateMouse(0.10f, 5.0f, 10.0f, &mouseTexture);
|
||||
}
|
||||
|
||||
void StartGame(App *app)
|
||||
{
|
||||
if(!app->state.gameStarted){
|
||||
app->state.gameStarted = true;
|
||||
}
|
||||
void StartGame(App *app) {
|
||||
if (!app->state.gameStarted) {
|
||||
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)
|
||||
{
|
||||
GameState *g = &app->game;
|
||||
if (app->flags.limitFPS){
|
||||
SetTargetFPS(60);
|
||||
} else {
|
||||
SetTargetFPS(0);
|
||||
}
|
||||
StartGame(app);
|
||||
|
||||
StartGame(app);
|
||||
OnEscapeChangeView(app, MENU);
|
||||
OnWindowClosedStoppApp(app);
|
||||
|
||||
OnEscapeChangeView(app, MENU);
|
||||
OnWindowClosedStoppApp(app);
|
||||
for (int i = 0; i < SHADER_COUNT; i++) {
|
||||
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++)
|
||||
{
|
||||
UpdatePostFX(&g->postFX[i]);
|
||||
}
|
||||
for (int i = 0; i < SOUNDTRACK_COUNT; i++)
|
||||
{
|
||||
UpdateSoundtrack(&g->soundtracks[i], app->flags.soundtrackOn);
|
||||
}
|
||||
|
||||
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);
|
||||
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)
|
||||
{
|
||||
GameState *g = &app->game;
|
||||
RenderFloor(&g->floor);
|
||||
RenderPlayer();
|
||||
RenderEnemies(&g->enemies);
|
||||
RenderBirds(&g->birds);
|
||||
RenderIslands(&g->islands);
|
||||
void RenderComponents(App *app) {
|
||||
GameState *g = &app->game;
|
||||
RenderFloor(&g->floor);
|
||||
RenderPlayer();
|
||||
RenderEnemies(&g->enemies);
|
||||
RenderBirds(&g->birds);
|
||||
RenderIslands(&g->islands);
|
||||
}
|
||||
|
||||
void RenderGame(App *app)
|
||||
{
|
||||
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();
|
||||
void RenderGame(App *app) {
|
||||
GameState *g = &app->game;
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
for (int i = 0; i < SHADER_COUNT; i++)
|
||||
{
|
||||
RenderPostFX(&g->postFX[i], &g->target);
|
||||
}
|
||||
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();
|
||||
|
||||
if (app->flags.showFPS)
|
||||
{
|
||||
DrawFPS(10, 10);
|
||||
}
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
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)
|
||||
{
|
||||
GameState *g = &app->game;
|
||||
for (int i = 0; i < SHADER_COUNT; i++)
|
||||
{
|
||||
UnloadPostFX(&g->postFX[i]);
|
||||
}
|
||||
for (int i = 0; i < SOUNDTRACK_COUNT; i++)
|
||||
{
|
||||
UnloadMusicStream(g->soundtracks[i].music);
|
||||
}
|
||||
UnloadRenderTexture(g->target);
|
||||
void CleanupGame(App *app) {
|
||||
GameState *g = &app->game;
|
||||
for (int i = 0; i < SHADER_COUNT; i++) {
|
||||
UnloadPostFX(&g->postFX[i]);
|
||||
}
|
||||
for (int i = 0; i < SOUNDTRACK_COUNT; i++) {
|
||||
UnloadMusicStream(g->soundtracks[i].music);
|
||||
}
|
||||
UnloadRenderTexture(g->target);
|
||||
}
|
||||
|
||||
|
||||
+27
-35
@@ -1,47 +1,39 @@
|
||||
#include "app.h"
|
||||
|
||||
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){
|
||||
TextureAsset islandAsset = islandsTextureAssets[ISLAND];
|
||||
Texture2D texture = LoadTexture(islandAsset.path);
|
||||
float frameWidth = islandAsset.frameWidth;
|
||||
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
|
||||
};
|
||||
Islands CreateIslands(void) {
|
||||
TextureAsset islandAsset = islandsTextureAssets[ISLAND];
|
||||
Texture2D texture = LoadTexture(islandAsset.path);
|
||||
float frameWidth = islandAsset.frameWidth;
|
||||
float rotation = islandAsset.rotation;
|
||||
|
||||
Physics islandPhysics = {
|
||||
.position = (Vector2){-100.0f, 0.0f},
|
||||
.direction = (Vector2){0.0f, 0.0f},
|
||||
.speed = 10.0f
|
||||
};
|
||||
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};
|
||||
|
||||
return (Islands){
|
||||
.sprite = islandSprite,
|
||||
.physics = islandPhysics
|
||||
};
|
||||
|
||||
Physics islandPhysics = {.position = (Vector2){-100.0f, 0.0f},
|
||||
.direction = (Vector2){0.0f, 0.0f},
|
||||
.speed = 10.0f};
|
||||
|
||||
return (Islands){.sprite = islandSprite, .physics = islandPhysics};
|
||||
}
|
||||
|
||||
void UpdateIslands(Islands *islands){
|
||||
|
||||
UpdatePhysics(&islands->physics, (Vector2){0.0f,0.0f});
|
||||
void UpdateIslands(Islands *islands) {
|
||||
|
||||
UpdatePhysics(&islands->physics, (Vector2){0.0f, 0.0f});
|
||||
UpdateSpriteDestRec(&islands->sprite, &islands->physics.position);
|
||||
UpdateAnimation(&islands->animation, GetFrameTime());
|
||||
UpdateSpriteSourceRec(&islands->sprite, &(Vector2){islands->sprite.frameSize.x * islands->animation.currentFrame, islands->sprite.frameSize.y});
|
||||
}
|
||||
|
||||
void RenderIslands(Islands *islands){
|
||||
RenderSprite(&islands->sprite);
|
||||
UpdateSpriteSourceRec(
|
||||
&islands->sprite,
|
||||
&(Vector2){islands->sprite.frameSize.x * islands->animation.currentFrame,
|
||||
islands->sprite.frameSize.y});
|
||||
}
|
||||
|
||||
void RenderIslands(Islands *islands) { RenderSprite(&islands->sprite); }
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "app.h"
|
||||
|
||||
Projectiles CreateProjectiles(void) {}
|
||||
|
||||
void UpdateProjectiles(Projectiles *projectiles) {}
|
||||
|
||||
void RenderProjectiles(Projectiles *projectiles) {}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "app.h"
|
||||
|
||||
Ship InitShip(int shipID) {
|
||||
Config config;
|
||||
InitConfig(&config, "config/ships.ini");
|
||||
Ship ship;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
#include "app.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user