-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmenu.h
83 lines (68 loc) · 1.83 KB
/
menu.h
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
#ifndef MENU_H
#define MENU_H
#include<SFML/Graphics.hpp>
#include<SFML/Audio.hpp>
#define No_of_Items 4
class Menu
{
private:
sf::Text text[No_of_Items];
static sf::Font font;
static sf::SoundBuffer sbuffer;
static sf::Sound click_sound;
int selectedItemIndex;
public:
static void LoadAssests ()
{
font.loadFromFile("cooper.ttf");
sbuffer.loadFromFile("sound\\click.ogg");
click_sound.setBuffer(sbuffer);
click_sound.setLoop(false);
}
Menu(int width, int height)
{
for(int i=0; i<No_of_Items; i++)
{
text[i].setFont(font);
text[i].setFillColor(sf::Color(255,255,255));
text[i].setPosition(width/2-100, 200+100*i);
}
text[0].setString("Play");
text[0].setFillColor(sf::Color(6,248,245));
text[1].setString("Instructions");
text[2].setString("High Score");
text[3].setString("Exit");
selectedItemIndex = 0;
}
~Menu () {}
void draw(sf::RenderWindow &window)
{
for(int i = 0; i< No_of_Items; i++)
{
window.draw(text[i]);
}
}
void MoveUp()
{
if(selectedItemIndex > 0)
{
text[selectedItemIndex].setFillColor(sf::Color::White);
selectedItemIndex--;
text[selectedItemIndex].setFillColor(sf::Color(6,245,248));
click_sound.play();
}
}
void MoveDown()
{
if(selectedItemIndex < No_of_Items)
{
text[selectedItemIndex].setFillColor(sf::Color::White);
selectedItemIndex++;
text[selectedItemIndex].setFillColor(sf::Color(6,245,248));
click_sound.play();
}
}
int GetPressedItem() {return selectedItemIndex;}
};
bool LoadMenu(sf::RenderWindow&, bool);
#endif // MENU_H