diff --git a/src/engine/applicationstate.h b/src/engine/applicationstate.h index 2681416..89335f4 100644 --- a/src/engine/applicationstate.h +++ b/src/engine/applicationstate.h @@ -5,6 +5,7 @@ typedef struct { Screen currentScreen; bool running; bool gameStarted; + bool flagFPS; } State; #endif // APPLICATIONSTATE_H diff --git a/src/game/game.h b/src/game/game.h index a92385c..dd40816 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -82,8 +82,6 @@ void UpdateGame(GameState* g, State *state){ UpdateFloor(&g->floor, &g->camera); UpdatePlayer(&g->player); UpdateBee(&g->bee1, &g->flowers, &g->hive); - - } void RenderComponents(GameState* g){ @@ -92,10 +90,9 @@ void RenderComponents(GameState* g){ RenderObjectArray(&g->flowers); RenderSprite(&g->player.sprite); RenderSprite(&g->bee1.sprite); - } -void RenderGame(GameState* g){ +void RenderGame(GameState* g, const State *appState){ BeginTextureMode(g->target); ClearBackground(BLACK); BeginMode2D(g->camera); @@ -109,7 +106,11 @@ void RenderGame(GameState* g){ RenderPostFX(&g->postFX[i], &g->target); } DrawText( TextFormat("%d", g->player.inventar.seedCount), 10, 10, 50, WHITE); - //DrawFPS(10, 10); + + if (appState->flagFPS){ + DrawFPS(10, 10); + } + EndDrawing(); } diff --git a/src/game/logo.h b/src/game/logo.h index b90725f..8087125 100644 --- a/src/game/logo.h +++ b/src/game/logo.h @@ -18,7 +18,6 @@ typedef struct { void InitLogo(LogoState *l) { SetTargetFPS(60); - l->frameCounter = 0; l->positionX = GetScreenWidth() / 2 - 128; l->positionY = GetScreenHeight() / 2 - 128; @@ -37,15 +36,15 @@ void UpdateLogo(LogoState *l, State *state) { state->running = false; } - l->frameCounter++; // Increment the frame counter each frame + l->frameCounter++; - if (l->state == 0) { // State 0: Small box blinking for 120 frames (2 seconds at 60 FPS) + if (l->state == 0) { if (l->frameCounter >= 120) { l->state = 1; - l->frameCounter = 0; // Reset frame counter + l->frameCounter = 0; } } - else if (l->state == 1) { // State 1: Top and left bars growing + else if (l->state == 1) { l->topSideRecWidth += 4; l->leftSideRecHeight += 4; @@ -54,7 +53,7 @@ void UpdateLogo(LogoState *l, State *state) { l->frameCounter = 0; } } - else if (l->state == 2) { // State 2: Bottom and right bars growing + else if (l->state == 2) { l->bottomSideRecWidth += 4; l->rightSideRecHeight += 4; @@ -63,12 +62,12 @@ void UpdateLogo(LogoState *l, State *state) { l->frameCounter = 0; } } - else if (l->state == 3) { // State 3: Letters appearing - if (l->frameCounter % 12 == 0) { // Every 12 frames, one more letter appears + else if (l->state == 3) { + if (l->frameCounter % 12 == 0) { l->lettersCount++; } - if (l->lettersCount >= 10) { // Fade out animation + if (l->lettersCount >= 10) { l->alpha -= 0.02f; if (l->alpha <= 0.0f) { l->alpha = 0.0f; @@ -76,31 +75,31 @@ void UpdateLogo(LogoState *l, State *state) { } } } - else if (l->state == 4) { // State 4: Transition to GAMEPLAY + else if (l->state == 4) { state->currentScreen = MENU; } } -void RenderLogo(const LogoState *l) { +void RenderLogo(const LogoState *l, const State *appState) { BeginDrawing(); ClearBackground(RAYWHITE); - if (l->state == 0) { // Small box blinking - if ((l->frameCounter / 15) % 2 == 0) { // Blink every 15 frames + if (l->state == 0) { + if ((l->frameCounter / 15) % 2 == 0) { DrawRectangle(l->positionX, l->positionY, 16, 16, BLACK); } } - else if (l->state == 1) { // Top and left bars growing + else if (l->state == 1) { DrawRectangle(l->positionX, l->positionY, l->topSideRecWidth, 16, BLACK); DrawRectangle(l->positionX, l->positionY, 16, l->leftSideRecHeight, BLACK); } - else if (l->state == 2) { // Bottom and right bars growing + else if (l->state == 2) { DrawRectangle(l->positionX, l->positionY, l->topSideRecWidth, 16, BLACK); DrawRectangle(l->positionX, l->positionY, 16, l->leftSideRecHeight, BLACK); DrawRectangle(l->positionX + 240, l->positionY, 16, l->rightSideRecHeight, BLACK); DrawRectangle(l->positionX, l->positionY + 240, l->bottomSideRecWidth, 16, BLACK); } - else if (l->state == 3) { // Letters appearing + else if (l->state == 3) { DrawRectangle(l->positionX, l->positionY, l->topSideRecWidth, 16, Fade(BLACK, l->alpha)); DrawRectangle(l->positionX, l->positionY + 16, 16, l->leftSideRecHeight - 32, Fade(BLACK, l->alpha)); DrawRectangle(l->positionX + 240, l->positionY + 16, 16, l->rightSideRecHeight - 32, Fade(BLACK, l->alpha)); @@ -110,7 +109,9 @@ void RenderLogo(const LogoState *l) { DrawText(TextSubtext("raylib", 0, l->lettersCount), GetScreenWidth() / 2 - 44, GetScreenHeight() / 2 + 48, 50, Fade(BLACK, l->alpha)); } - DrawFPS(10, 10); + if (appState->flagFPS){ + DrawFPS(10, 10); + } EndDrawing(); } diff --git a/src/game/menu.h b/src/game/menu.h index 40506e5..eddcd81 100644 --- a/src/game/menu.h +++ b/src/game/menu.h @@ -124,7 +124,7 @@ void UpdateMenu(MenuState *m, State *state){ } -void RenderMenu(MenuState *m, Font *font, const char* name){ +void RenderMenu(MenuState *m, State *appState,Font *font, const char* name){ BeginDrawing(); ClearBackground(WHITE); RenderBackground(&m->background); @@ -142,8 +142,12 @@ void RenderMenu(MenuState *m, Font *font, const char* name){ (Vector2){0.0f, 0.0f}, 0.0f, WHITE - ); - DrawFPS(10, 10); + ); + + if (appState->flagFPS){ + DrawFPS(10, 10); + } + EndDrawing(); } diff --git a/src/main.c b/src/main.c index a375e58..168b15f 100644 --- a/src/main.c +++ b/src/main.c @@ -34,6 +34,7 @@ int main(void) app.state.currentScreen = LOGO; app.state.running = true; app.state.gameStarted = false; + app.state.flagFPS = true; app.display = display; app.font = LoadFont("assets/SproutLandsUI/fonts/pixelFont-7-8x14-sproutLands.fnt"); @@ -51,17 +52,17 @@ int main(void) case LOGO: { UpdateLogo(&app.logo, &app.state); - RenderLogo(&app.logo); + RenderLogo(&app.logo, &app.state); }break; case MENU: { UpdateMenu(&app.menu, &app.state); - RenderMenu(&app.menu, &app.font, app.display.name); + RenderMenu(&app.menu, &app.state, &app.font, app.display.name); }break; case GAMEPLAY: { UpdateGame(&app.game, &app.state); - RenderGame(&app.game); + RenderGame(&app.game, &app.state); }break; default: break; }