El Octavio  1.0
This is a video game about adventures.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Menu.cpp
Go to the documentation of this file.
1#include "../Header files/Precompile.h"
2#include "../Header files/Menu.h"
3#include "../Header files/El Octavo-Functions.h"
4#include "../Header files/Additional Functions.h"
5
6bool audioToggle = true;
7bool showFPS = true;
8
9namespace variables {
11
14
16
18
20
22
24}
25
26using namespace variables;
27
28void setupMenu(RenderWindow& window);
29
31{
32 if (!music.openFromFile("../Audios/Main.ogg"))
33 {
34 cout << "Error" << endl;
35 }
36
37 if (audioToggle)
38 {
39 music.play();
40 }
41 else {
42 cout << "";
43 }
44
45 checkButtonTexture.loadFromFile("../Images and fonts/Bg/OptionChecked.png");
46
47 for (int i = 0; i < 2; i++)
48 {
50 }
51
52 if (setPositionByDefault == true)
53 {
54 checkButtonImage[0].setPosition(369, 395);
55 checkButtonImage[1].setPosition(782, 395);
57 }
58 else {
59 cout << "";
60 }
61
62
63 addIcon(window);
64 music.setLoop(true);
65}
66
68{
69 texture.loadFromFile("../Images and fonts/Bg/OptionsMenu.png");
70
71 while (true)
72 {
73 Sprite sprite(texture);
74
75 while (window.pollEvent(ev))
76 {
77 switch (ev.type)
78 {
79 case Event::MouseButtonPressed:
80 {
81 switch (ev.key.code)
82 {
83 case Mouse::Left:
84 {
85 if ((ev.mouseButton.x >= 357 && ev.mouseButton.x <= 428) && (ev.mouseButton.y >= 384 && ev.mouseButton.y <= 455))
86 {
87 audioToggle = true;
88
89 if (audioToggle)
90 {
91 cout << "";
92 }
93 else {
94 music.stop();
95 }
96
97 checkButtonImage[0].setPosition(369, 395);
98 }
99
100 else if ((ev.mouseButton.x >= 465 && ev.mouseButton.x <= 536) && (ev.mouseButton.y >= 384 && ev.mouseButton.y <= 455))
101 {
102 audioToggle = false;
103
104 if (audioToggle)
105 {
106 cout << "";
107 }
108 else {
109 music.stop();
110 }
111
112 checkButtonImage[0].setPosition(477, 395);
113 }
114
115 else if ((ev.mouseButton.x >= 770 && ev.mouseButton.x <= 841) && (ev.mouseButton.y >= 384 && ev.mouseButton.y <= 455))
116 {
117 showFPS = true;
118
119 checkButtonImage[1].setPosition(782, 395);
120 }
121
122 else if ((ev.mouseButton.x >= 878 && ev.mouseButton.x <= 949) && (ev.mouseButton.y >= 384 && ev.mouseButton.y <= 455))
123 {
124 showFPS = false;
125
126 checkButtonImage[1].setPosition(890, 395);
127 }
128
129 else if ((ev.mouseButton.x >= 1054 && ev.mouseButton.x <= 1197) && (ev.mouseButton.y >= 593 && ev.mouseButton.y <= 637))
130 {
131 setupMenu(window);
132 }
133 break;
134 }
135 break;
136 }
137 }
138 }
139 }
140
141 window.draw(sprite);
142
143 for (int i = 0; i < 2; i++)
144 {
145 window.draw(checkButtonImage[i]);
146 }
147
148 window.display();
149 }
150}
151
153{
154 setupVars(window);
155
156 textureMenu.loadFromFile("../Images and fonts/Bg/Menu.png");
158 bgImageMenu.setOrigin(1280 / 2, 720 / 2);
159 bgImageMenu.setPosition(window.getSize().x / 2, window.getSize().y / 2);
160
161 while (window.isOpen())
162 {
163 while (window.pollEvent(evMenu))
164 {
165
166 if (evMenu.type == Event::Closed)
167 {
168 window.close();
169 }
170
171 if (evMenu.type == Event::KeyPressed && evMenu.key.code == Keyboard::Escape)
172 {
173 window.close();
174 }
175
176 switch (evMenu.type)
177 {
178 case Event::MouseButtonPressed:
179 {
180 switch (evMenu.key.code)
181 {
182 case Mouse::Left:
183
184 if (evMenu.mouseButton.x >= 530 && evMenu.mouseButton.x <= 750)
185 {
186 if (evMenu.mouseButton.y >= 335 && evMenu.mouseButton.y <= 392)
187 {
188 music.stop();
189
191 setup(window);
192 }
193
194 if (evMenu.mouseButton.y >= 459 && evMenu.mouseButton.y <= 516)
195 {
196 optionMenu(evMenu, texture, window);
197 }
198
199 if (evMenu.mouseButton.y >= 581 && evMenu.mouseButton.y <= 638)
200 {
201 window.close();
202 }
203 }
204 break;
205 }
206 }
207 }
208 }
209
210 window.draw(bgImageMenu);
211
212 window.display();
213 }
214}
215
217{
218 return audioToggle;
219}
220
222{
223 return showFPS;
224}
void addIcon(RenderWindow &window)
void backstory(RenderWindow &window, Texture backstoryTexture, Sprite backstoryImage)
Sprite backstoryImage
Texture backstoryTexture
void setup(RenderWindow &window)
bool audioToggle
Definition: Menu.cpp:6
void optionMenu(Event &ev, Texture texture, RenderWindow &window)
Definition: Menu.cpp:67
void setupMenu(RenderWindow &window)
Definition: Menu.cpp:152
bool showFPS
Definition: Menu.cpp:7
bool isAudioRunning(bool &audioToggle)
Definition: Menu.cpp:216
bool isShowingFPS(bool &showFPS)
Definition: Menu.cpp:221
void setupVars(RenderWindow &window)
Definition: Menu.cpp:30
Defines a system event and its parameters.
Definition: Event.hpp:45
MouseButtonEvent mouseButton
Mouse button event parameters (Event::MouseButtonPressed, Event::MouseButtonReleased)
Definition: Event.hpp:227
KeyEvent key
Key event parameters (Event::KeyPressed, Event::KeyReleased)
Definition: Event.hpp:224
EventType type
Type of the event.
Definition: Event.hpp:219
Streamed music played from an audio file.
Definition: Music.hpp:49
bool openFromFile(const std::string &filename)
Open a music from an audio file.
void draw(const Drawable &drawable, const RenderStates &states=RenderStates::Default)
Draw a drawable object to the render target.
Window that can serve as a target for 2D drawing.
virtual Vector2u getSize() const
Get the size of the rendering region of the window.
void stop()
Stop playing the audio stream.
void setLoop(bool loop)
Set whether or not the stream should loop after reaching the end.
void play()
Start or resume playing the audio stream.
Drawable representation of a texture, with its own transformations, color, etc.
Definition: Sprite.hpp:48
void setTexture(const Texture &texture, bool resetRect=false)
Change the source texture of the sprite.
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:49
bool loadFromFile(const std::string &filename, const IntRect &area=IntRect())
Load the texture from a file on disk.
void setPosition(float x, float y)
set the position of the object
void setOrigin(float x, float y)
set the local origin of the object
T x
X coordinate of the vector.
Definition: Vector2.hpp:75
T y
Y coordinate of the vector.
Definition: Vector2.hpp:76
bool pollEvent(Event &event)
Pop the event on top of the event queue, if any, and return it.
void close()
Close the window and destroy all the attached resources.
void display()
Display on screen what has been rendered to the window so far.
bool isOpen() const
Tell whether or not the window is open.
Sprite checkButtonImage[2]
Definition: Menu.cpp:21
Texture checkButtonTexture
Definition: Menu.cpp:19
Texture textureMenu
Definition: Menu.cpp:12
Event evMenu
Definition: Menu.cpp:10
Music music
Definition: Menu.cpp:15
bool setPositionByDefault
Definition: Menu.cpp:23
Texture texture
Definition: Menu.cpp:17
Sprite bgImageMenu
Definition: Menu.cpp:13
Keyboard::Key code
Code of the key that has been pressed.
Definition: Event.hpp:64
int x
X position of the mouse pointer, relative to the left of the owner window.
Definition: Event.hpp:98
int y
Y position of the mouse pointer, relative to the top of the owner window.
Definition: Event.hpp:99