diff --git a/src/engine/gui.h b/src/engine/gui.h index d61c167..ba69c01 100644 --- a/src/engine/gui.h +++ b/src/engine/gui.h @@ -7,10 +7,10 @@ typedef struct { Rectangle rec; - const char *text; + char *text; } Button; -void initButton(Button *b, const char *text, int buttonWidth, int buttonHeight, int buttonPosX, int buttonPosY) +void initButton(Button *b, char *text, int buttonWidth, int buttonHeight, int buttonPosX, int buttonPosY) { b->rec = (Rectangle){buttonPosX - buttonWidth / 2, buttonPosY - buttonHeight / 2, buttonWidth, buttonHeight}; b->text = text; diff --git a/src/game/game.h b/src/game/game.h index aa8f47b..0dc1654 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -66,7 +66,7 @@ void InitGame(GameState* g){ g->target = LoadRenderTexture(GetScreenWidth(), GetScreenHeight()); } -void UpdateGame(GameState* g, Screen *currentScreen){ +void UpdateGame(GameState* g, Screen *currentScreen, bool *running, bool *gameStarted){ UpdatePostFX(&g->postFX); UpdateMusic(&g->ambient); UpdateMouse(&g->mouse, &g->camera); diff --git a/src/game/menu.h b/src/game/menu.h index 62580c9..7c4dec2 100644 --- a/src/game/menu.h +++ b/src/game/menu.h @@ -5,22 +5,30 @@ typedef struct { Button startButton; + Button quitButton; } MenuState; void InitMenu(MenuState *t){ initButton(&t->startButton, "Start Game", GetScreenWidth() / 10, GetScreenHeight() / 20, GetScreenWidth() / 2, GetScreenHeight() / 2); + initButton(&t->quitButton, "Quit Game", GetScreenWidth() / 10, GetScreenHeight() / 20, GetScreenWidth() / 2, GetScreenHeight() / 2 + GetScreenHeight() / 20); } -void UpdateMenu(MenuState *t, Screen *currentScreen){ +void UpdateMenu(MenuState *t, Screen *currentScreen, bool *running, bool *gameStarted){ if (isButtonClicked(&t->startButton)) { + *gameStarted = true; + t->startButton.text = "Continue"; *currentScreen = GAMEPLAY; } + if (isButtonClicked(&t->quitButton)) { + *running = false; + } } void RenderMenu(MenuState *t){ BeginDrawing(); ClearBackground(WHITE); renderButton(&t->startButton); + renderButton(&t->quitButton); EndDrawing(); } diff --git a/src/main.c b/src/main.c index 33847d4..fa67309 100644 --- a/src/main.c +++ b/src/main.c @@ -10,46 +10,56 @@ int main(void) { - Settings settings = { + + typedef struct { + Screen currentScreen; + bool running; + bool gameStarted; + Settings settings; + LogoState logo; + GameState game; + MenuState menu; + } Application; + + Application app; + app.currentScreen = LOGO; + app.running = true; + app.gameStarted = false; + app.settings = (Settings){ .name = "The Last Hive", .screenWidth = 1280, .screenHeight = 720 }; - InitWindow(settings.screenWidth, settings.screenHeight, settings.name); - - Screen currentScreen = GAMEPLAY; - LogoState logo; - GameState game; - MenuState menu; + InitWindow(app.settings.screenWidth, app.settings.screenHeight, app.settings.name); - InitLogo(&logo); - InitMenu(&menu); - InitGame(&game); + InitLogo(&app.logo); + InitMenu(&app.menu); + InitGame(&app.game); - while (true) + while (app.running) { - switch (currentScreen) + switch (app.currentScreen) { case LOGO: { - UpdateLogo(&logo,¤tScreen); - RenderLogo(&logo); + UpdateLogo(&app.logo,&app.currentScreen); + RenderLogo(&app.logo); }break; case MENU: { - UpdateMenu(&menu, ¤tScreen); - RenderMenu(&menu); + UpdateMenu(&app.menu, &app.currentScreen, &app.running, &app.gameStarted); + RenderMenu(&app.menu); }break; case GAMEPLAY: { - UpdateGame(&game, ¤tScreen); - RenderGame(&game); + UpdateGame(&app.game, &app.currentScreen, &app.running, &app.gameStarted); + RenderGame(&app.game); }break; default: break; } } - CleanupGame(&game); + CleanupGame(&app.game); CloseWindow(); return 0; }