appstate flag for fps drawing
This commit is contained in:
@@ -5,6 +5,7 @@ typedef struct {
|
|||||||
Screen currentScreen;
|
Screen currentScreen;
|
||||||
bool running;
|
bool running;
|
||||||
bool gameStarted;
|
bool gameStarted;
|
||||||
|
bool flagFPS;
|
||||||
} State;
|
} State;
|
||||||
|
|
||||||
#endif // APPLICATIONSTATE_H
|
#endif // APPLICATIONSTATE_H
|
||||||
|
|||||||
+6
-5
@@ -82,8 +82,6 @@ void UpdateGame(GameState* g, State *state){
|
|||||||
UpdateFloor(&g->floor, &g->camera);
|
UpdateFloor(&g->floor, &g->camera);
|
||||||
UpdatePlayer(&g->player);
|
UpdatePlayer(&g->player);
|
||||||
UpdateBee(&g->bee1, &g->flowers, &g->hive);
|
UpdateBee(&g->bee1, &g->flowers, &g->hive);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderComponents(GameState* g){
|
void RenderComponents(GameState* g){
|
||||||
@@ -92,10 +90,9 @@ void RenderComponents(GameState* g){
|
|||||||
RenderObjectArray(&g->flowers);
|
RenderObjectArray(&g->flowers);
|
||||||
RenderSprite(&g->player.sprite);
|
RenderSprite(&g->player.sprite);
|
||||||
RenderSprite(&g->bee1.sprite);
|
RenderSprite(&g->bee1.sprite);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderGame(GameState* g){
|
void RenderGame(GameState* g, const State *appState){
|
||||||
BeginTextureMode(g->target);
|
BeginTextureMode(g->target);
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
BeginMode2D(g->camera);
|
BeginMode2D(g->camera);
|
||||||
@@ -109,7 +106,11 @@ void RenderGame(GameState* g){
|
|||||||
RenderPostFX(&g->postFX[i], &g->target);
|
RenderPostFX(&g->postFX[i], &g->target);
|
||||||
}
|
}
|
||||||
DrawText( TextFormat("%d", g->player.inventar.seedCount), 10, 10, 50, WHITE);
|
DrawText( TextFormat("%d", g->player.inventar.seedCount), 10, 10, 50, WHITE);
|
||||||
//DrawFPS(10, 10);
|
|
||||||
|
if (appState->flagFPS){
|
||||||
|
DrawFPS(10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-17
@@ -18,7 +18,6 @@ typedef struct {
|
|||||||
|
|
||||||
void InitLogo(LogoState *l) {
|
void InitLogo(LogoState *l) {
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
l->frameCounter = 0;
|
l->frameCounter = 0;
|
||||||
l->positionX = GetScreenWidth() / 2 - 128;
|
l->positionX = GetScreenWidth() / 2 - 128;
|
||||||
l->positionY = GetScreenHeight() / 2 - 128;
|
l->positionY = GetScreenHeight() / 2 - 128;
|
||||||
@@ -37,15 +36,15 @@ void UpdateLogo(LogoState *l, State *state) {
|
|||||||
state->running = false;
|
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) {
|
if (l->frameCounter >= 120) {
|
||||||
l->state = 1;
|
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->topSideRecWidth += 4;
|
||||||
l->leftSideRecHeight += 4;
|
l->leftSideRecHeight += 4;
|
||||||
|
|
||||||
@@ -54,7 +53,7 @@ void UpdateLogo(LogoState *l, State *state) {
|
|||||||
l->frameCounter = 0;
|
l->frameCounter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (l->state == 2) { // State 2: Bottom and right bars growing
|
else if (l->state == 2) {
|
||||||
l->bottomSideRecWidth += 4;
|
l->bottomSideRecWidth += 4;
|
||||||
l->rightSideRecHeight += 4;
|
l->rightSideRecHeight += 4;
|
||||||
|
|
||||||
@@ -63,12 +62,12 @@ void UpdateLogo(LogoState *l, State *state) {
|
|||||||
l->frameCounter = 0;
|
l->frameCounter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (l->state == 3) { // State 3: Letters appearing
|
else if (l->state == 3) {
|
||||||
if (l->frameCounter % 12 == 0) { // Every 12 frames, one more letter appears
|
if (l->frameCounter % 12 == 0) {
|
||||||
l->lettersCount++;
|
l->lettersCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l->lettersCount >= 10) { // Fade out animation
|
if (l->lettersCount >= 10) {
|
||||||
l->alpha -= 0.02f;
|
l->alpha -= 0.02f;
|
||||||
if (l->alpha <= 0.0f) {
|
if (l->alpha <= 0.0f) {
|
||||||
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;
|
state->currentScreen = MENU;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderLogo(const LogoState *l) {
|
void RenderLogo(const LogoState *l, const State *appState) {
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
if (l->state == 0) { // Small box blinking
|
if (l->state == 0) {
|
||||||
if ((l->frameCounter / 15) % 2 == 0) { // Blink every 15 frames
|
if ((l->frameCounter / 15) % 2 == 0) {
|
||||||
DrawRectangle(l->positionX, l->positionY, 16, 16, BLACK);
|
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, l->topSideRecWidth, 16, BLACK);
|
||||||
DrawRectangle(l->positionX, l->positionY, 16, l->leftSideRecHeight, 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, l->topSideRecWidth, 16, BLACK);
|
||||||
DrawRectangle(l->positionX, l->positionY, 16, l->leftSideRecHeight, BLACK);
|
DrawRectangle(l->positionX, l->positionY, 16, l->leftSideRecHeight, BLACK);
|
||||||
DrawRectangle(l->positionX + 240, l->positionY, 16, l->rightSideRecHeight, BLACK);
|
DrawRectangle(l->positionX + 240, l->positionY, 16, l->rightSideRecHeight, BLACK);
|
||||||
DrawRectangle(l->positionX, l->positionY + 240, l->bottomSideRecWidth, 16, 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, l->topSideRecWidth, 16, Fade(BLACK, l->alpha));
|
||||||
DrawRectangle(l->positionX, l->positionY + 16, 16, l->leftSideRecHeight - 32, 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));
|
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));
|
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();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-3
@@ -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();
|
BeginDrawing();
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
RenderBackground(&m->background);
|
RenderBackground(&m->background);
|
||||||
@@ -142,8 +142,12 @@ void RenderMenu(MenuState *m, Font *font, const char* name){
|
|||||||
(Vector2){0.0f, 0.0f},
|
(Vector2){0.0f, 0.0f},
|
||||||
0.0f,
|
0.0f,
|
||||||
WHITE
|
WHITE
|
||||||
);
|
);
|
||||||
DrawFPS(10, 10);
|
|
||||||
|
if (appState->flagFPS){
|
||||||
|
DrawFPS(10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -34,6 +34,7 @@ int main(void)
|
|||||||
app.state.currentScreen = LOGO;
|
app.state.currentScreen = LOGO;
|
||||||
app.state.running = true;
|
app.state.running = true;
|
||||||
app.state.gameStarted = false;
|
app.state.gameStarted = false;
|
||||||
|
app.state.flagFPS = true;
|
||||||
app.display = display;
|
app.display = display;
|
||||||
app.font = LoadFont("assets/SproutLandsUI/fonts/pixelFont-7-8x14-sproutLands.fnt");
|
app.font = LoadFont("assets/SproutLandsUI/fonts/pixelFont-7-8x14-sproutLands.fnt");
|
||||||
|
|
||||||
@@ -51,17 +52,17 @@ int main(void)
|
|||||||
case LOGO:
|
case LOGO:
|
||||||
{
|
{
|
||||||
UpdateLogo(&app.logo, &app.state);
|
UpdateLogo(&app.logo, &app.state);
|
||||||
RenderLogo(&app.logo);
|
RenderLogo(&app.logo, &app.state);
|
||||||
}break;
|
}break;
|
||||||
case MENU:
|
case MENU:
|
||||||
{
|
{
|
||||||
UpdateMenu(&app.menu, &app.state);
|
UpdateMenu(&app.menu, &app.state);
|
||||||
RenderMenu(&app.menu, &app.font, app.display.name);
|
RenderMenu(&app.menu, &app.state, &app.font, app.display.name);
|
||||||
}break;
|
}break;
|
||||||
case GAMEPLAY:
|
case GAMEPLAY:
|
||||||
{
|
{
|
||||||
UpdateGame(&app.game, &app.state);
|
UpdateGame(&app.game, &app.state);
|
||||||
RenderGame(&app.game);
|
RenderGame(&app.game, &app.state);
|
||||||
}break;
|
}break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user