-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPauseMenu.cpp
More file actions
107 lines (91 loc) · 3.3 KB
/
PauseMenu.cpp
File metadata and controls
107 lines (91 loc) · 3.3 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
103
104
105
106
#include "PauseMenu.h"
void PauseMenu::initTextures()
{
if (!background.loadFromFile("Textures/pauseMenu_background.png")) { cout << "No texture found" << endl; }
bufferTick.loadFromFile("Textures/menuTick.wav");
soundTick.setBuffer(bufferTick);
}
void PauseMenu::initSprites(RenderWindow& gameWindow)
{
backgroundSprite.setTexture(background);
backgroundSprite.setScale(VideoMode::getDesktopMode().width/1280.f, VideoMode::getDesktopMode().height /720.f);
}
void PauseMenu::initTexts(Font& gameFont, RenderWindow& gameWindow)
{
texts[0].setFont(gameFont);
texts[0].setString("PAUSE MENU");
texts[0].setPosition(gameWindow.getSize().x / 3.5, gameWindow.getSize().y / 14);
texts[0].setCharacterSize(130);
texts[0].setFillColor(Color::White);
texts[0].setOutlineColor(Color::Black);
texts[0].setOutlineThickness(2);
texts[1].setFont(gameFont);
texts[1].setString("Continue");
texts[1].setPosition(gameWindow.getSize().x / 2.5, gameWindow.getSize().y / 3);
texts[1].setFillColor(Color::White);
texts[1].setCharacterSize(80);
texts[1].setOutlineColor(Color::Black);
texts[1].setOutlineThickness(2);
texts[2].setFont(gameFont);
texts[2].setString("Exit Game");
texts[2].setPosition(gameWindow.getSize().x / 2.55, gameWindow.getSize().y / 2.2);
texts[2].setCharacterSize(80);
texts[2].setFillColor(Color::White);
texts[2].setOutlineColor(Color::Black);
texts[2].setOutlineThickness(2);
}
void PauseMenu::update(RenderWindow& gameWindow)
{
if (Mouse::getPosition(gameWindow).x > texts[1].getGlobalBounds().left && Mouse::getPosition(gameWindow).x < (texts[1].getGlobalBounds().left + texts[1].getGlobalBounds().width) && Mouse::getPosition(gameWindow).y > texts[1].getGlobalBounds().top && Mouse::getPosition(gameWindow).y < texts[1].getGlobalBounds().top + texts[1].getGlobalBounds().height) {
if (selectedButton != Continue) soundTick.play();
selectedButton = Continue;
mouseOnButton = continue1;
}
else if (Mouse::getPosition(gameWindow).x > texts[2].getGlobalBounds().left && Mouse::getPosition(gameWindow).x < texts[2].getGlobalBounds().left + texts[2].getGlobalBounds().width && Mouse::getPosition(gameWindow).y > texts[2].getGlobalBounds().top && Mouse::getPosition(gameWindow).y < texts[2].getGlobalBounds().top + texts[2].getGlobalBounds().height) {
if (selectedButton != Exit) soundTick.play();
selectedButton = Exit;
mouseOnButton = exit;
}
else { mouseOnButton = none; }
if (selectedButton == Continue) {
texts[1].setFillColor(Color::Green);
texts[2].setFillColor(Color::White);
}
else if (selectedButton == Exit) {
texts[2].setFillColor(Color::Green);
texts[1].setFillColor(Color::White);
}
}
PauseMenu::PauseMenu(Font& gameFont, RenderWindow& gameWindow)
{
initTextures();
initSprites(gameWindow);
initTexts(gameFont, gameWindow);
selectedButton = Continue;
}
void PauseMenu::display(RenderWindow& gameWindow, Time* elapsed)
{
update(gameWindow);
gameWindow.draw(backgroundSprite);
for (int i = 0; i < 3; i++) {
gameWindow.draw(texts[i]);
}
}
void PauseMenu::selectUp()
{
if (selectedButton != Continue) soundTick.play();
selectedButton = Continue;
}
void PauseMenu::selectDown()
{
if (selectedButton != Exit) soundTick.play();
selectedButton = Exit;
}
int PauseMenu::returnSelectedButton()
{
return selectedButton;
}
int PauseMenu::returnMouseOnButton()
{
return mouseOnButton;
}