From fd0c7d4a5a23f6e8bfbafbed7d9bde319607451d Mon Sep 17 00:00:00 2001 From: nathansmithsmith Date: Fri, 22 Dec 2023 01:08:20 -0700 Subject: Started working on the how to play screen --- src/game.c | 7 +++++++ src/game.h | 5 ++++- src/howToPlayScreen.c | 13 +++++++++++++ src/howToPlayScreen.h | 13 +++++++++++++ src/mainMenu.c | 21 ++++++++++++++------- src/mainMenu.h | 3 ++- 6 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 src/howToPlayScreen.c create mode 100644 src/howToPlayScreen.h diff --git a/src/game.c b/src/game.c index 594646d..e39901e 100644 --- a/src/game.c +++ b/src/game.c @@ -19,6 +19,9 @@ void initGame(Game * game) { // Main menu. initMainMenu(game); + // How to play screen. + initHowToPlayScreen(game); + // Camera. initCameras(game, game->cameras); @@ -49,6 +52,8 @@ void closeGame(Game * game) { void gameResize(Game * game) { resizeGameScreen(game, &game->gameScreen); + resizeMainMenu(game, &game->mainMenu); + resizeHowToPlayScreen(game, &game->howToPlayScreen); } void updateGame(Game * game) { @@ -61,6 +66,8 @@ void updateGame(Game * game) { case SCREEN_GAME: updateGameScreen(game); break; + case HOW_TO_PLAY_SCREEN: + updateHowToPlayScreen(game); default: break; } diff --git a/src/game.h b/src/game.h index 41084c4..74252e6 100644 --- a/src/game.h +++ b/src/game.h @@ -9,19 +9,22 @@ #include "bullets.h" #include "levels.h" #include "killLog.h" +#include "howToPlayScreen.h" #ifndef GAME_H #define GAME_H typedef enum ScreenId { SCREEN_MAIN_MENU, - SCREEN_GAME + SCREEN_GAME, + HOW_TO_PLAY_SCREEN } ScreenId; typedef struct Game { ScreenId screenId; MainMenu mainMenu; GameScreen gameScreen; + HowToPlayScreen howToPlayScreen; Cameras cameras; Assets assets; World world; diff --git a/src/howToPlayScreen.c b/src/howToPlayScreen.c new file mode 100644 index 0000000..abd7a01 --- /dev/null +++ b/src/howToPlayScreen.c @@ -0,0 +1,13 @@ +#include "howToPlayScreen.h" +#include "game.h" + +void initHowToPlayScreen(Game * game) { +} + +void updateHowToPlayScreen(Game * game) { + ClearBackground(RAYWHITE); + DrawText("hi", 100, 100, 20, BLACK); +} + +void resizeHowToPlayScreen(Game * game, HowToPlayScreen * howToPlayScreen) { +} diff --git a/src/howToPlayScreen.h b/src/howToPlayScreen.h new file mode 100644 index 0000000..86b720d --- /dev/null +++ b/src/howToPlayScreen.h @@ -0,0 +1,13 @@ +#include "gameCommon.h" + +#ifndef HOW_TO_PLAY_SCREEN_H +#define HOW_TO_PLAY_SCREEN_H + +typedef struct HowToPlayScreen { +} HowToPlayScreen; + +void initHowToPlayScreen(Game * game); +void updateHowToPlayScreen(Game * game); +void resizeHowToPlayScreen(Game * game, HowToPlayScreen * howToPlayScreen); + +#endif diff --git a/src/mainMenu.c b/src/mainMenu.c index c0568f9..8cc2b09 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -4,11 +4,12 @@ void initMainMenu(Game * game) { game->mainMenu = (MainMenu){ - .startButton = (Rectangle){0, 0, 100, 50}, + .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); + resizeMainMenu(game, &game->mainMenu); } void updateMainMenu(Game * game) { @@ -28,13 +29,14 @@ void updateMainMenu(Game * game) { if (start) openGameScreen(game); - if (IsWindowResized()) - resizeMainMenu(game); -} + // How to play button. + bool clickedHowToPlay = GuiButton(mainMenu->howToPlayButton, "How to play"); -void resizeMainMenu(Game * game) { - MainMenu * mainMenu = &game->mainMenu; + 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), @@ -44,4 +46,9 @@ void resizeMainMenu(Game * game) { // 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; } diff --git a/src/mainMenu.h b/src/mainMenu.h index 10ce855..c8bae78 100644 --- a/src/mainMenu.h +++ b/src/mainMenu.h @@ -8,10 +8,11 @@ typedef struct MainMenu { Texture2D * logoTexture; Rectangle startButton; + Rectangle howToPlayButton; } MainMenu; void initMainMenu(Game * game); void updateMainMenu(Game * game); -void resizeMainMenu(Game * game); +void resizeMainMenu(Game * game, MainMenu * mainMenu); #endif -- cgit v1.2.3