1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#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},
.infoButton = (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
);
if (GuiButton(mainMenu->startButton, "Start"))
openGameScreen(game);
if (GuiButton(mainMenu->howToPlayButton, "How to play"))
game->screenId= HOW_TO_PLAY_SCREEN;
if (GuiButton(mainMenu->infoButton, "Info"))
game->screenId = INFO_SCREEN;
}
void resizeMainMenu(Game * game, MainMenu * mainMenu) {
int width = GetScreenWidth();
int height = GetScreenHeight();
// Logo.
mainMenu->logoPosition = (Vector2){
(width / 2.0) - (mainMenu->logoTexture->width / 2.0),
(height / 2.0) - (mainMenu->logoTexture->height * 1.50)
};
// Start button.
mainMenu->startButton.x = (width / 2.0) - (mainMenu->startButton.width / 2.0);
mainMenu->startButton.y = (height / 2.0) - (mainMenu->startButton.height / 2.0);
// How to play button.
mainMenu->howToPlayButton.x = (width / 2.0) - (mainMenu->startButton.width / 2.0);
mainMenu->howToPlayButton.y = (height / 2.0) - (mainMenu->startButton.height / 2.0);
mainMenu->howToPlayButton.y += mainMenu->startButton.height;
// Info button.
mainMenu->infoButton.x = (width / 2.0) - (mainMenu->infoButton.width / 2.0);
mainMenu->infoButton.y = mainMenu->howToPlayButton.height + mainMenu->howToPlayButton.y;
}
|