-
Notifications
You must be signed in to change notification settings - Fork 0
/
difficulty.cpp
134 lines (109 loc) · 4.67 KB
/
difficulty.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
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
#include "init.h"
#include "game.cpp"
#include "button.h"
#include "pages.h"
#include "multiplayer.cpp"
#pragma once
using namespace sf;
void difficulty(RenderWindow &window, VideoMode &mode){
Button easy(mode, "EASY", pathToDirectory + "fonts/font.ttf", Color::Red, 0);
Button medium(mode, "MEDIUM", pathToDirectory + "fonts/font.ttf", Color::Red, 1);
Button hard(mode, "HARD", pathToDirectory + "fonts/font.ttf", Color::Red, 2);
Button multiplayer(mode, "MULTIPLAYER", pathToDirectory + "fonts/font.ttf", Color::Red, 3);
Button back(mode, "BACK", pathToDirectory + "fonts/font.ttf", Color::Red);
Sprite spriteCursor(textureCursor0);
setCursor(window, spriteCursor);
Event event;
Clock clock;
Time time = clock.getElapsedTime();
bool changeColor = false;
int color = 0;
while(window.isOpen()){
while(window.pollEvent(event)){
if (event.type == Event::Closed){
window.close();
}
if (event.type == event.MouseButtonReleased)
spriteCursor.setTexture(textureCursor0);
if (event.type == event.MouseButtonPressed)
spriteCursor.setTexture(textureCursor1);
if(event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Left &&
isInsideButton(Vector2f(Mouse::getPosition(window).x, Mouse::getPosition(window).y), easy.sprite)){
soundsAll.sound[9].play();
musicAll.music[numberMusicMenu].pause();
WindowSent windowSent(window, mode, 0.2);
Thread thread(&openGame, windowSent);
thread.launch();
thread.wait();
musicAll.music[numberMusicMenu].play();
return;
}
else if(event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Left &&
isInsideButton(Vector2f(Mouse::getPosition(window).x, Mouse::getPosition(window).y), medium.sprite)){
soundsAll.sound[9].play();
musicAll.music[numberMusicMenu].pause();
WindowSent windowSent(window, mode, 1);
Thread thread(&openGame, windowSent);
thread.launch();
thread.wait();
musicAll.music[numberMusicMenu].play();
return;
}
else if(event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Left &&
isInsideButton(Vector2f(Mouse::getPosition(window).x, Mouse::getPosition(window).y), hard.sprite)){
soundsAll.sound[9].play();
musicAll.music[numberMusicMenu].pause();
WindowSent windowSent(window, mode, 5);
Thread thread(&openGame, windowSent);
thread.launch();
thread.wait();
musicAll.music[numberMusicMenu].play();
return;
}
else if(event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Left &&
isInsideButton(Vector2f(Mouse::getPosition(window).x, Mouse::getPosition(window).y), multiplayer.sprite)){
soundsAll.sound[9].play();
musicAll.music[numberMusicMenu].pause();
WindowSent windowSent(window, mode, 1);
Thread thread(&openMultiplayer, windowSent);
thread.launch();
thread.wait();
musicAll.music[numberMusicMenu].play();
return;
}
if(event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Left &&
isInsideButton(Vector2f(Mouse::getPosition(window).x, Mouse::getPosition(window).y), back.sprite)){
soundsAll.sound[9].play();
return;
}
}
easy.update(window);
medium.update(window);
hard.update(window);
multiplayer.update(window);
back.update(window);
updateCursor(window, spriteCursor);
time = clock.restart();
if(!changeColor){
color += (int)(time.asSeconds() * 200);
if(color > 255){
color = 255;
changeColor = true;
}
} else{
color -= (int)(time.asSeconds() * 200);
if(color < 50){
color = 50;
changeColor = false;
}
}
window.clear(Color(100, 100, color, 0));
easy.draw(window);
medium.draw(window);
hard.draw(window);
multiplayer.draw(window);
back.draw(window);
window.draw(spriteCursor);
window.display();
}
}