Skip to content

Commit c5d4182

Browse files
committed
attempting shape for buttons
1 parent 0cf0b60 commit c5d4182

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/button.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
#include "button.h"
22

3-
Button InitButton(Texture2D text, Vector2 offset, Sound soundFx, GameState state)
3+
Button InitButton(Texture2D texture, const char *text, Vector2 offset, Sound soundFx, GameState state)
44
{
55
// Define frame rectangle for drawing
6-
float height = (float)text.height / BUTTON_FRAMES;
7-
Rectangle sourceRec = {0, 0, (float)text.width, height};
6+
float height = (float)texture.height / BUTTON_FRAMES;
7+
Rectangle sourceRec = {0, 0, (float)texture.width, height};
88

99
// Define button position on screen
1010
Rectangle btnPosition = {
11-
screenWidth / 2.0f - text.width / 2.0f + offset.x,
12-
screenHeight / 2.0f - text.height / BUTTON_FRAMES / 2.0f + offset.y,
13-
(float)text.width,
11+
screenWidth / 2.0f - texture.width / 2.0f + offset.x,
12+
screenHeight / 2.0f - texture.height / BUTTON_FRAMES / 2.0f + offset.y,
13+
(float)texture.width,
1414
height};
1515

1616
return (Button){
17-
.texture = text,
17+
.texture = texture,
18+
.text = text,
1819
.rect = sourceRec,
1920
.position = btnPosition,
2021
.frameHeight = height,
@@ -63,5 +64,7 @@ void UpdateButton(Button *button)
6364

6465
void DrawButton(Button *button)
6566
{
66-
DrawTextureRec(button->texture, button->rect, (Vector2){button->position.x, button->position.y}, WHITE);
67+
// DrawTextureRec(button->texture, button->rect, (Vector2){button->position.x, button->position.y}, WHITE);
68+
DrawRectangle(button->position.x, button->position.y, button->rect.x, button->rect.y, LIGHTGRAY);
69+
DrawText(button->text, button->position.x + 40, button->position.y + 10, 40, BLACK);
6770
}

src/button.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
typedef struct Button
1212
{
1313
Texture2D texture;
14+
const char *text;
1415
Rectangle rect;
1516
Rectangle position;
1617
float frameHeight;
@@ -19,7 +20,7 @@ typedef struct Button
1920
GameState selectedState;
2021
} Button;
2122

22-
Button InitButton(Texture2D text, Vector2 offset, Sound soundFx, GameState state);
23+
Button InitButton(Texture2D texture, const char *text, Vector2 offset, Sound soundFx, GameState state);
2324
void UpdateButton(Button *button);
2425
void DrawButton(Button *button);
2526

src/raylib_game.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ int main(void)
109109
Sound blip = LoadSound("resources/blip_select.ogg");
110110

111111
// UI -------------------------------------------------
112-
Button playButton = InitButton(playTexture, (Vector2){.x = 0.f, .y = -360.f}, blip, GAME_PLAY);
113-
Button creditsButton = InitButton(creditsTexture, (Vector2){.x = 0.f, .y = -200.f}, blip, GAME_CREDITS);
114-
Button exitButton = InitButton(exitTexture, (Vector2){.x = 0.f, .y = -40.f}, blip, GAME_EXIT);
115-
Button menuButton = InitButton(menuTexture, (Vector2){.x = 0.f, .y = 360.f}, blip, GAME_MENU);
112+
Button playButton = InitButton(playTexture, "play", (Vector2){.x = 0.f, .y = -360.f}, blip, GAME_PLAY);
113+
Button creditsButton = InitButton(creditsTexture, "credits", (Vector2){.x = 0.f, .y = -200.f}, blip, GAME_CREDITS);
114+
Button exitButton = InitButton(exitTexture, "exit", (Vector2){.x = 0.f, .y = -40.f}, blip, GAME_EXIT);
115+
Button menuButton = InitButton(menuTexture, "menu", (Vector2){.x = 0.f, .y = 360.f}, blip, GAME_MENU);
116116

117117
MainMenu mainMenu = InitMainMenu(&playButton, &creditsButton, &exitButton);
118118
ScoreMenu scoreMenu = InitScoreMenu(&playButton, &menuButton);

0 commit comments

Comments
 (0)