-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pause.cpp
81 lines (70 loc) · 1.79 KB
/
Pause.cpp
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
#pragma
#include "Pause.h"
Pause::Pause()
{
_continueTexture.loadFromFile("assets/CONTINUAR.png");
_continueSprite.setTexture(_continueTexture);
_exitTexture.loadFromFile("assets/PAUSA_SALIR.png");
_exitSprite.setTexture(_exitTexture);
_pauseMenuSelection = 0;
_selectedOption = -1;
_paused = false;
}
void Pause::update(sf::Event event)
{
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Down) {
_pauseMenuSelection = (_pauseMenuSelection + 1) % 2; // Alternates between 0 and
}
else if (event.key.code == sf::Keyboard::Up) {
_pauseMenuSelection = (_pauseMenuSelection + 1) % 2; // Alternates between 0 and 1
}
else if (event.key.code == sf::Keyboard::Enter) {
if (_pauseMenuSelection == 0) {
_buffer.loadFromFile("assets/sounds/smw_save_menu.wav");
_sound.setBuffer(_buffer);
_sound.play();
_selectedOption = 0;
}
else if (_pauseMenuSelection == 1) {
_selectedOption = 1;
}
}
else if (event.key.code == sf::Keyboard::Escape) {
_buffer.loadFromFile("assets/sounds/smw_save_menu.wav");
_sound.setBuffer(_buffer);
_sound.play();
_selectedOption = 0;
}
}
}
void Pause::render(sf::RenderWindow& window) {
sf::View currentView = window.getView();
sf::Vector2f centerPosition = currentView.getCenter();
if (_pauseMenuSelection == 0) {
_continueSprite.setPosition(centerPosition.x - 400.0f, 0.0f);
window.draw(_continueSprite);
}
else if (_pauseMenuSelection == 1) {
_exitSprite.setPosition(centerPosition.x - 400.0f, 0.0f);
window.draw(_exitSprite);
}
}
bool Pause::getPaused() const
{
return _paused;
}
void Pause::open()
{
_pauseMenuSelection = 0;
_selectedOption = -1;
_paused = true;
}
void Pause::close()
{
_paused = false;
}
int Pause::getSelectedOption() const
{
return _selectedOption;
}