-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainMenu.cpp
More file actions
86 lines (64 loc) · 1.74 KB
/
Copy pathMainMenu.cpp
File metadata and controls
86 lines (64 loc) · 1.74 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
#include "../include/MainMenu.hpp"
#include "../include/DemoLevel.hpp"
MainMenu::MainMenu()
: BasicScene()
{
}
MainMenu::~MainMenu()
{
}
void MainMenu::initialize(sf::RenderWindow& window)
{
font.loadFromFile("WorknameProject/Fonts/MainMenuFont.ttf");
logo = sf::Text("</> WorkName Project", font, 64U);
logo.setOrigin(logo.getGlobalBounds().width / 2.0f, 0.0f);
logo.setPosition(window.getSize().x / 2.0f, 0.0f);
playButton = sf::Text("Play", font, 44U);
playButton.setOrigin(playButton.getGlobalBounds().width / 2.0f, 0.0f);
playButton.setPosition(window.getSize().x / 2.0f, logo.getGlobalBounds().height * 1.5f);
quitButton = sf::Text("Quit", font, 44U);
quitButton.setOrigin(quitButton.getGlobalBounds().width / 2.0f, 0.0f);
quitButton.setPosition(window.getSize().x / 2, logo.getGlobalBounds().height * 1.5f + playButton.getGlobalBounds().height * 1.5f);
selected = BUTTON_PLAY;
}
BasicScene* MainMenu::update(sf::RenderWindow& window, float)
{
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S) && selected > BUTTON_QUIT)
{
selected--;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W) && selected < BUTTON_PLAY)
{
selected++;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Return))
{
switch(selected)
{
case BUTTON_QUIT:
window.close();
break;
case BUTTON_PLAY:
active = false;
return new DemoLevel;
}
}
return this;
}
void MainMenu::render(sf::RenderWindow& window)
{
playButton.setColor(sf::Color::White);
quitButton.setColor(sf::Color::White);
switch(selected)
{
case BUTTON_QUIT:
quitButton.setColor(sf::Color(128, 0, 0));
break;
case BUTTON_PLAY:
playButton.setColor(sf::Color(128, 0, 0));
break;
}
window.draw(logo);
window.draw(playButton);
window.draw(quitButton);
}