diff options
Diffstat (limited to 'src/screens/mainMenu.c')
-rw-r--r-- | src/screens/mainMenu.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/screens/mainMenu.c b/src/screens/mainMenu.c new file mode 100644 index 0000000..8cc2b09 --- /dev/null +++ b/src/screens/mainMenu.c @@ -0,0 +1,54 @@ +#include "mainMenu.h" +#include "game.h" +#include "gameScreen.h" + +void initMainMenu(Game * game) { + game->mainMenu = (MainMenu){ + .startButton = (Rectangle){0.0, 0.0, 100.0, 50.0}, + .howToPlayButton = (Rectangle){0.0, 0.0, 100.0, 50.0}, + .logoTexture = &game->assets.textures[ICON128_ASSET] + }; + + resizeMainMenu(game, &game->mainMenu); +} + +void updateMainMenu(Game * game) { + MainMenu * mainMenu = &game->mainMenu; + ClearBackground(RAYWHITE); + + // Logo. + DrawTextureV( + *mainMenu->logoTexture, + mainMenu->logoPosition, + WHITE + ); + + // Start button. + bool start = GuiButton(mainMenu->startButton, "Start"); + + if (start) + openGameScreen(game); + + // How to play button. + bool clickedHowToPlay = GuiButton(mainMenu->howToPlayButton, "How to play"); + + if (clickedHowToPlay) + game->screenId= HOW_TO_PLAY_SCREEN; +} + +void resizeMainMenu(Game * game, MainMenu * mainMenu) { + // Logo. + mainMenu->logoPosition = (Vector2){ + (GetScreenWidth() / 2.0) - (mainMenu->logoTexture->width / 2.0), + (GetScreenHeight() / 2.0) - (mainMenu->logoTexture->height * 1.50) + }; + + // Start button. + mainMenu->startButton.x = (GetScreenWidth() / 2.0) - (mainMenu->startButton.width / 2.0); + mainMenu->startButton.y = (GetScreenHeight() / 2.0) - (mainMenu->startButton.height / 2.0); + + // How to play button. + mainMenu->howToPlayButton.x = (GetScreenWidth() / 2.0) - (mainMenu->startButton.width / 2.0); + mainMenu->howToPlayButton.y = (GetScreenHeight() / 2.0) - (mainMenu->startButton.height / 2.0); + mainMenu->howToPlayButton.y += mainMenu->startButton.height; +} |