-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameMenu.cpp
More file actions
102 lines (87 loc) · 1.97 KB
/
GameMenu.cpp
File metadata and controls
102 lines (87 loc) · 1.97 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include "GameMenu.h"
#include "GameSettings.h"
GameMenu::GameMenu(sf::RenderWindow* window, GameStateManager* gameStateManager)
{
this->window = window;
this->gameStateManager = gameStateManager;
}
void GameMenu::Init()
{
if (!font.loadFromFile("./Assets/Fonts/landsand.otf"))
{
std::cout << "Failed font load!" << std::endl;
}
title = sf::Text("Maze", font, 160);
sf::Vector2u winSize = window->getSize();
sf::FloatRect titleRect = title.getLocalBounds();
title.setOrigin(sf::Vector2f(titleRect.left + titleRect.width / 2.0f, titleRect.top + titleRect.height / 2.0f));
title.setPosition(sf::Vector2f(winSize.x/2.f, 2.f * (winSize.y / 9.f )));
buttons["start"] = new Button("Start", sf::Vector2f(winSize.x / 2.f, 5.f * (winSize.y / 9.f)), sf::Vector2f(200.f, 100.f), 70);
buttons["exit"] = new Button("Exit", sf::Vector2f(winSize.x / 2.f, 7.f * (winSize.y / 9.f)), sf::Vector2f(200.f, 100.f), 70);
}
void GameMenu::Cleanup()
{
for (auto const& elem : buttons)
{
delete elem.second;
}
buttons.clear();
}
void GameMenu::Pause()
{
}
void GameMenu::Resume()
{
}
void GameMenu::GetEvents()
{
sf::Event event;
while (window->pollEvent(event))
{
if (event.type == sf::Event::Closed)
window->close();
if (event.type == sf::Event::MouseButtonReleased)
{
for (auto const& elem : buttons)
{
if (elem.second->mouseHover(window))
{
if (elem.first == "exit")
{
window->close();
}
else if (elem.first == "start")
{
gameStateManager->ChangeState(new GameSettings(window, gameStateManager));
return;
}
}
}
}
}
for (auto const& elem : buttons)
{
if (elem.second->mouseHover(window))
{
elem.second->setHover();
}
else
{
elem.second->setDefault();
}
}
}
void GameMenu::Update()
{
}
void GameMenu::Display()
{
window->clear(sf::Color::Black);
window->draw(title);
for (auto const& elem : buttons)
{
window->draw(*(elem.second));
}
window->display();
}