aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathansmith117 <thenathansmithsmith@gmail.com>2024-02-21 02:57:18 +0000
committernathansmith117 <thenathansmithsmith@gmail.com>2024-02-21 02:57:18 +0000
commit6c63c3d327cf3b494309db82bdd4489b59d3d247 (patch)
treea5222a6e960e74f884299a558d8b103efcd6804d
parent801df9c821db87cf2e50f486c63ff083b375eb7e (diff)
downloadPenguinYippies-6c63c3d327cf3b494309db82bdd4489b59d3d247.tar.gz
PenguinYippies-6c63c3d327cf3b494309db82bdd4489b59d3d247.tar.bz2
PenguinYippies-6c63c3d327cf3b494309db82bdd4489b59d3d247.zip
Button thingy working
-rw-r--r--src/gameScreen.c1
-rw-r--r--src/mainMenu.c32
-rw-r--r--src/mainMenu.h2
-rw-r--r--src/ui.c31
-rw-r--r--src/ui.h4
5 files changed, 70 insertions, 0 deletions
diff --git a/src/gameScreen.c b/src/gameScreen.c
index 23e12cf..bfdbf6e 100644
--- a/src/gameScreen.c
+++ b/src/gameScreen.c
@@ -7,6 +7,7 @@ void initGameScreen(GameScreen* gameScreen, Game* game)
void updateGameScreen(GameScreen* gameScreen, Game* game)
{
+ ClearBackground(RAYWHITE);
}
void closeGameScreen(GameScreen* gameScreen)
diff --git a/src/mainMenu.c b/src/mainMenu.c
index 6041e4b..f64c2be 100644
--- a/src/mainMenu.c
+++ b/src/mainMenu.c
@@ -4,10 +4,33 @@
void initMainMenu(MainMenu* mainMenu, Game* game)
{
+ // Start button stuff.
mainMenu->startButtonAnimation = createAnimation(
&game->assets.animations[BUTTON_BOX_ANIMATION],
ANIMATION_DEFAULT_DELAY
);
+
+ playAnimation(&mainMenu->startButtonAnimation);
+
+ Texture* startButtonTexture = &mainMenu->startButtonAnimation.texture;
+
+ int width = GetScreenWidth();
+ int height = GetScreenHeight();
+
+ mainMenu->startButton = createTexturedButton(
+ startButtonTexture,
+ (Rectangle){
+ width / 2.0 - startButtonTexture->width / 2.0,
+ height / 2.0 - startButtonTexture->height,
+ startButtonTexture->width,
+ startButtonTexture->height
+ },
+ "Start",
+ WHITE,
+ BLACK
+ );
+
+ mainMenu->startButton.fontSize = 50;
}
void updateMainMenu(MainMenu* mainMenu, Game* game)
@@ -23,6 +46,15 @@ void updateMainMenu(MainMenu* mainMenu, Game* game)
0.0,
WHITE
);
+
+ // Draw start button.
+ runAnimation(&mainMenu->startButtonAnimation);
+ bool startPressed = updateTexturedButton(&mainMenu->startButton);
+
+ if (startPressed)
+ {
+ game->currentScreen = GAME_SCREEN;
+ }
}
void closeMainMenu(MainMenu* mainMenu)
diff --git a/src/mainMenu.h b/src/mainMenu.h
index f2722a3..1396183 100644
--- a/src/mainMenu.h
+++ b/src/mainMenu.h
@@ -1,11 +1,13 @@
#include "gameCommon.h"
#include "animation.h"
+#include "ui.h"
#ifndef MAIN_MENU_H
#define MAIN_MENU_H
typedef struct MainMenu {
Animation startButtonAnimation;
+ TexturedButton startButton;
} MainMenu;
void initMainMenu(MainMenu* mainMenu, Game* game);
diff --git a/src/ui.c b/src/ui.c
index d0e9aa3..7166add 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -7,9 +7,13 @@ TexturedButton createTexturedButton(Texture* texture, Rectangle rect, const char
TexturedButton button;
button.texture = texture;
button.rect = rect;
+
strncpy((char*)button.message, message, UI_BUTTON_NAME_MAX);
+ button.messageLength = strnlen(button.message, UI_BUTTON_NAME_MAX);
+
button.backgroundColor = backgroundColor;
button.foregroundColor = foregroundColor;
+ button.fontSize = UI_BUTTON_DEFAULT_FONT_SIZE;
button.isPressed = false;
return button;
@@ -27,5 +31,32 @@ bool updateTexturedButton(TexturedButton* button)
button->backgroundColor
);
+
+ // Draw outline thingy.
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
+ {
+ DrawRectangleLinesEx(button->rect, 2, button->foregroundColor);
+ }
+
+ // Draw text centered in button.
+ DrawText(
+ button->message,
+ button->rect.x + (button->rect.width / 2.0 - (button->messageLength * button->fontSize / 4.0)),
+ button->rect.y + (button->rect.height / 2.0 - button->fontSize / 2.0),
+ button->fontSize,
+ button->foregroundColor
+ );
+
+ button->isPressed = false;
+
+ // Check if the button is clicked.
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
+ {
+ if (CheckCollisionPointRec(GetMousePosition(), button->rect))
+ {
+ button->isPressed = true;
+ }
+ }
+
return button->isPressed;
}
diff --git a/src/ui.h b/src/ui.h
index 717435b..7d487d5 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -1,6 +1,7 @@
#include "gameCommon.h"
#define UI_BUTTON_NAME_MAX 50
+#define UI_BUTTON_DEFAULT_FONT_SIZE 20
#ifndef UI_H
#define UI_H
@@ -10,10 +11,13 @@ typedef struct TexturedButton {
Rectangle rect;
char message[UI_BUTTON_NAME_MAX];
+ size_t messageLength;
Color backgroundColor;
Color foregroundColor;
+ int fontSize;
+
bool isPressed;
} TexturedButton;