aboutsummaryrefslogtreecommitdiff
path: root/src/mainMenu.c
blob: c0568f9ff1803a96bbe5114f3782743a84bd1bec (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
#include "mainMenu.h"
#include "game.h"
#include "gameScreen.h"

void initMainMenu(Game * game) {
	game->mainMenu = (MainMenu){
		.startButton = (Rectangle){0, 0, 100, 50},
		.logoTexture = &game->assets.textures[ICON128_ASSET]
	};

	resizeMainMenu(game);
}

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);

	if (IsWindowResized())
		resizeMainMenu(game);
}

void resizeMainMenu(Game * game) {
	MainMenu * mainMenu = &game->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);
}