-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
128 lines (111 loc) · 2.92 KB
/
Copy pathMenu.cpp
File metadata and controls
128 lines (111 loc) · 2.92 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "menu.h"
Menu::Menu(sf::RenderWindow* janela){
window = janela;
font = new sf::Font();
image = new sf::Texture();
bg = new sf::Sprite();
window->setPosition(sf::Vector2i(0, 0));
pos = 0;
pressed = theselect = false;
font->loadFromFile("./times-new-roman-bold-italic.ttf");
image->loadFromFile("./menu.png");
bg->setTexture(*image);
}
Menu::~Menu(){
window=nullptr;
delete font;
delete image;
delete bg;
}
void Menu::set_values(int tipo){
if (tipo == 1) {
options = { "zelda++", "iniciar","continuar", "ranking"};
numOpcoes = 3;
texts.resize(4);
coords = { {654,58},{592,257},{592,415},{592,550} };
sizes = { 124,103,103, 103 };
}
else if (tipo == 2) {
options = { "zelda++", "1 jogador", "2 jogadores"};
numOpcoes = 2;
texts.resize(3);
coords = { {677,55},{655,247},{655,453} };
sizes = { 124,103,103, };
}
else if (tipo == 3) {
options = { "zelda++", "Fase 1", "Fase 2" };
numOpcoes = 2;
texts.resize(3);
coords = { {677,55},{655,247},{655,453} };
sizes = { 124,103,103, };
}
else if (tipo == 4) {
options = { "Pause", "despausar", "menu","salvar e sair"};
numOpcoes = 3;
texts.resize(4);
coords = { {654,58},{592,257},{592,415},{592,550} };
sizes = { 124,103,103,103 };
}
for (std::size_t i{}; i < texts.size(); ++i){
texts[i].setFont(*font);
texts[i].setString(options[i]);
texts[i].setCharacterSize(sizes[i]);
texts[i].setFillColor(sf::Color(228, 58, 20));
texts[i].setOutlineColor(sf::Color::White);
texts[i].setPosition(coords[i]);
}
texts[1].setOutlineThickness(4);
pos = 1;
}
int Menu::loop_events(){
sf::Event event;
while(window->pollEvent(event)){
if( event.type == sf::Event::Closed){
window->close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && !pressed){
if( pos < numOpcoes){
++pos;
pressed = true;
texts[pos].setOutlineThickness(4);
texts[pos - 1].setOutlineThickness(0);
pressed = false;
theselect = false;
return 0;
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && !pressed){
if( pos > 1){
--pos;
pressed = true;
texts[pos].setOutlineThickness(4);
texts[pos + 1].setOutlineThickness(0);
pressed = false;
theselect = false;
return 0;
}
}
if (!sf::Keyboard::isKeyPressed(sf::Keyboard::Enter) && theselect) {
theselect = false;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Enter) && !theselect){
theselect = true;
texts[pos].setOutlineThickness(0);
return pos;
}
return 0;
}
}
void Menu::draw_all(){
window->clear();
window->draw(*bg);
for(auto t : texts){
window->draw(t);
}
window->display();
}
int Menu::run_menu(){
int output=loop_events();
draw_all();
return output;
}