-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmenu.cpp
More file actions
67 lines (57 loc) · 1.86 KB
/
Copy pathmenu.cpp
File metadata and controls
67 lines (57 loc) · 1.86 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
#include "SFML/Graphics.hpp"
#include "SFML/Graphics/Text.hpp"
#include "Narrative.cpp"
using namespace sf;
#define MAX_NUMBER_OF_ITEMS 2
class Menu{
private:
int selectedItemIndex;
Font font;
Button menu[MAX_NUMBER_OF_ITEMS];
Text header;
public:
Menu(){
if(!font.loadFromFile("arial.ttf")){}
header.setFont(font);
header.setFillColor(Color::Blue);
header.setString("Welcome to the World of Adventure");
header.setPosition(Vector2f(10, 50));
menu[0] = Button(Vector2f(20,250), 300, 50, font, "Start the Adventure");
menu[1] = Button(Vector2f(20, 450), 100, 50, font, "Exit");
selectedItemIndex = 0;
}
void draw(RenderWindow &window){
window.draw(header);
for (int i = 0; i < MAX_NUMBER_OF_ITEMS; i++){
menu[i].drawButton(window);
}
}
void handleEvents(RenderWindow &window){
Event event;
while (window.pollEvent(event)){
switch (event.type) {
case Event::Closed:
window.close();
break;
case Event::MouseButtonPressed:
if (event.mouseButton.button == Mouse::Left){
Vector2f mousePos = window.mapPixelToCoords(Mouse::getPosition(window));
if(menu[1].isClicked(mousePos)){
window.close();
}else if(menu[0].isClicked(mousePos)){
while(window.isOpen()){
window.clear();
Narrative story;
story.handleEvents(window);
story.drawCharacterMenu(window);
window.display();
}
}
}
break;
default:
break;
}
}
}
};