-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.cpp
118 lines (101 loc) · 3.53 KB
/
display.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
#include "display.h"
Display::Display(float width, float height) {
selectplay.loadFromFile("C:\\work\\cwork\\testSfml\\pushplay.png");
selecthelp.loadFromFile("C:\\work\\cwork\\testSfml\\pushhelp.png");
selectexit.loadFromFile("C:\\work\\cwork\\testSfml\\pushexit.png");
help.loadFromFile("C:\\work\\cwork\\testSfml\\help.png");
exit.loadFromFile("C:\\work\\cwork\\testSfml\\exit.png");
play.loadFromFile("C:\\work\\cwork\\testSfml\\play.png");
selecteasy.loadFromFile("C:\\work\\cwork\\testSfml\\easysel.png");
selectmedium.loadFromFile("C:\\work\\cwork\\testSfml\\mediumsel.png");
selecthard.loadFromFile("C:\\work\\cwork\\testSfml\\hardsel.png");
easy.loadFromFile("C:\\work\\cwork\\testSfml\\easy.png");
medium.loadFromFile("C:\\work\\cwork\\testSfml\\medium.png");
hard.loadFromFile("C:\\work\\cwork\\testSfml\\hard.png");
menu[0].setTexture(selectplay);
menu[1].setTexture(help);
menu[2].setTexture(exit);
menu[0].setPosition(sf::Vector2f(width / 2, height / (itemnumber + 2) * 0.4));
menu[1].setPosition(sf::Vector2f(width / 2, height / (itemnumber + 2) * 1.9));
menu[2].setPosition(sf::Vector2f(width / 2, height / (itemnumber + 2) * 3.5));
selectedItemIndex = 0;
diffc[0].setTexture(selecteasy);
diffc[1].setTexture(medium);
diffc[2].setTexture(hard);
diffc[0].setPosition(sf::Vector2f(width / (itemnumber + 2) * 0.4, height * 0.9));
diffc[1].setPosition(sf::Vector2f(width / (itemnumber + 2) * 1.9, height * 0.9));
diffc[2].setPosition(sf::Vector2f(width / (itemnumber + 2) * 3.5, height * 0.9));
selectedDifficulty = 0;
}
Display::~Display() {
}
int Display::GetPressedItem() {
return this->selectedItemIndex;
}
void Display::drawMenu(sf::RenderWindow& window) {
for (int i = 0; i < itemnumber; i++) {
window.draw(menu[i]);
window.draw(diffc[i]);
}
}
void Display::drawHelp(sf::RenderWindow& window) {
sf::Texture gHelp;
gHelp.loadFromFile("C:\\work\\cwork\\testSfml\\ghelp.png");
sf::Sprite showHelp;
showHelp.setTexture(gHelp);
showHelp.setPosition(0, 0);
window.draw(showHelp);
}
void Display::MoveUp() {
//»èÁ¦
if (selectedItemIndex == 2) {
menu[selectedItemIndex].setTexture(exit);
selectedItemIndex--;
menu[selectedItemIndex].setTexture(selecthelp);
}
else if (selectedItemIndex == 1) {
menu[selectedItemIndex].setTexture(help);
selectedItemIndex--;
menu[selectedItemIndex].setTexture(selectplay);
}
}
void Display::MoveDown() {
//»èÁ¦
if (selectedItemIndex == 0) {
menu[selectedItemIndex].setTexture(play);
selectedItemIndex++;
menu[selectedItemIndex].setTexture(selecthelp);
}
else if (selectedItemIndex == 1) {
menu[selectedItemIndex].setTexture(help);
selectedItemIndex++;
menu[selectedItemIndex].setTexture(selectexit);
}
}
int Display::GetDifficulty() {
return selectedDifficulty;
}
void Display::MoveLeft() {
if (selectedDifficulty == 2) {
diffc[selectedDifficulty].setTexture(hard);
selectedDifficulty--;
diffc[selectedDifficulty].setTexture(selectmedium);
}
else if (selectedDifficulty == 1) {
diffc[selectedDifficulty].setTexture(medium);
selectedDifficulty--;
diffc[selectedDifficulty].setTexture(selecteasy);
}
}
void Display::MoveRight() {
if (selectedDifficulty == 0) {
diffc[selectedDifficulty].setTexture(easy);
selectedDifficulty++;
diffc[selectedDifficulty].setTexture(selectmedium);
}
else if (selectedDifficulty == 1) {
diffc[selectedDifficulty].setTexture(medium);
selectedDifficulty++;
diffc[selectedDifficulty].setTexture(selecthard);
}
}