aboutsummaryrefslogtreecommitdiff
path: root/src/screens/mainMenu.c
blob: 8cc2b097b1627cc05edb673372ec192144a3fc3e (plain)
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
#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;
}