This repository was archived by the owner on Sep 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
211 lines (186 loc) · 6.54 KB
/
Copy pathMenu.cpp
File metadata and controls
211 lines (186 loc) · 6.54 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//
// Created by joseph on 3/25/17.
//
#include <iostream>
#include "Menu.h"
#include "Utils.h"
Menu::Menu()
{
alpha_max = 3 * 255;
alpha_div = 3;
playing = false;
}
int Menu::run(sf::RenderWindow &window, sf::Texture &pauseTexture, Options* gameOptions)
{
sf::Event event;
bool running = true;
sf::Texture bgTexture;
sf::Sprite bg;
int alpha = 0;
sf::Font verdana;
sf::Font classicFont;
sf::Text logo;
sf::Text playLabel;
sf::Text exitLabel;
sf::Text optionsLabel;
sf::Text creditsLabel;
sf::Text continueLabel;
sf::Text copyLabel;
sf::Text rakingsLabel;
int menu = 0;
if (!bgTexture.loadFromFile("Resources/menu/presentation.jpg"))
{
std::cerr << "Error loading presentation.jpg" << std::endl;
return (-1);
}
if (!classicFont.loadFromFile("Resources/menu/8bit.ttf"))
{
std::cerr << "Error loading 8bit.ttf" << std::endl;
return (-1);
}
bg.setTexture(bgTexture);
bg.setColor(sf::Color(255, 255, 255, alpha));
playLabel.setFont(classicFont);
playLabel.setCharacterSize(40);
playLabel.setString("Play");
playLabel.setPosition({ 300.f, 350.f });
optionsLabel.setFont(classicFont);
optionsLabel.setCharacterSize(40);
optionsLabel.setString("Options");
optionsLabel.setPosition({ 300.f, 400.f });
rakingsLabel.setFont(classicFont);
rakingsLabel.setCharacterSize(40);
rakingsLabel.setString("High scores");
rakingsLabel.setPosition({ 300.f, 450.f });
creditsLabel.setFont(classicFont);
creditsLabel.setCharacterSize(40);
creditsLabel.setString("Credits");
creditsLabel.setPosition({ 300.f, 500.f });
exitLabel.setFont(classicFont);
exitLabel.setCharacterSize(40);
exitLabel.setString("Exit");
exitLabel.setPosition({ 300.f, 550.f });
logo.setFont(classicFont);
logo.setCharacterSize(200);
logo.setString("XeonWars");
sf::FloatRect textRect = logo.getLocalBounds();
logo.setOrigin(textRect.left + textRect.width/2.0f,
textRect.top + textRect.height/2.0f);
logo.setPosition({ window.getSize().x/2.f, 200.f });
copyLabel.setFont(classicFont);
copyLabel.setCharacterSize(40);
copyLabel.setString("(C) 2017 Ximenathl and co");
textRect = copyLabel.getLocalBounds();
copyLabel.setOrigin(textRect.left + textRect.width/2.0f,
textRect.top + textRect.height/2.0f);
copyLabel.setPosition({ 1366/2.0f, 700.f });
while (running)
{
//Verifying events
while (window.pollEvent(event))
{
if (event.type == sf::Event::Resized)
window.setView(Utils::calcView(sf::Vector2u(event.size.width, event.size.height), Utils::designedsize));
// Window closed
if (event.type == sf::Event::Closed)
{
return (-1);
}
//Key pressed
if (event.type == sf::Event::KeyPressed)
{
switch (event.key.code)
{
case sf::Keyboard::Escape:
return -1;
case sf::Keyboard::Up:
menu--;
if (menu<0)
menu = 0;
break;
case sf::Keyboard::Down:
menu++;
if (menu>4)
menu = 4;
break;
case sf::Keyboard::Return:
if (menu == 0) {
return (1);
} else if (menu == 1) {
return (4);
} else if (menu == 2) {
return (6);
} else if (menu == 3) {
return(5);
} else {
return (-1);
}
default:
break;
}
}
}
//When getting at alpha_max, we stop modifying the sprite
if (alpha<alpha_max)
{
alpha+=3;
}
bg.setColor(sf::Color(255, 255, 255, alpha / alpha_div));
if (menu == 0)
{
playLabel.setColor(sf::Color(255, 0, 0, 255));
optionsLabel.setColor(sf::Color(255, 255, 255, 255));
rakingsLabel.setColor(sf::Color(255, 255, 255, 255));
creditsLabel.setColor(sf::Color(255, 255, 255, 255));
exitLabel.setColor(sf::Color(255, 255, 255, 255));
}
else if (menu == 1)
{
playLabel.setColor(sf::Color(255, 255, 255, 255));
optionsLabel.setColor(sf::Color(255, 0, 0, 255));
rakingsLabel.setColor(sf::Color(255, 255, 255, 255));
creditsLabel.setColor(sf::Color(255, 255, 255, 255));
exitLabel.setColor(sf::Color(255, 255, 255, 255));
} else if (menu == 2) {
playLabel.setColor(sf::Color(255, 255, 255, 255));
optionsLabel.setColor(sf::Color(255, 255, 255, 255));
rakingsLabel.setColor(sf::Color(255, 0, 0, 255));
creditsLabel.setColor(sf::Color(255, 255, 255, 255));
exitLabel.setColor(sf::Color(255, 255, 255, 255));
}
else if (menu == 3)
{
playLabel.setColor(sf::Color(255, 255, 255, 255));
optionsLabel.setColor(sf::Color(255, 255, 255, 255));
rakingsLabel.setColor(sf::Color(255, 255, 255, 255));
creditsLabel.setColor(sf::Color(255, 0, 0, 255));
exitLabel.setColor(sf::Color(255, 255, 255, 255));
}
else
{
playLabel.setColor(sf::Color(255, 255, 255, 255));
optionsLabel.setColor(sf::Color(255, 255, 255, 255));
rakingsLabel.setColor(sf::Color(255, 255, 255, 255));
creditsLabel.setColor(sf::Color(255, 255, 255, 255));
exitLabel.setColor(sf::Color(255, 0, 0, 255));
}
//Clearing screen
window.clear();
//Drawing
window.draw(bg);
if (alpha >= alpha_max)
alpha = alpha_max;
{
window.draw(playLabel);
window.draw(copyLabel);
window.draw(logo);
window.draw(optionsLabel);
window.draw(creditsLabel);
window.draw(exitLabel);
window.draw(rakingsLabel);
}
window.display();
}
//Never reaching this point normally, but just in case, exit the application
return (-1);
}