-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
51 lines (41 loc) · 1.27 KB
/
Menu.cpp
File metadata and controls
51 lines (41 loc) · 1.27 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
#include "stdafx.h"
#include "Menu.h"
Menu::Menu() {};
Menu::Menu(float screenWidth, float screenHeight) {
width = screenWidth;
height = screenHeight;
menuTitle = Text("P O N G", sf::Color::White, 50, sf::Vector2f((width / 4) * 1.5, (height / 4) * 1));
menuText.push_back(Text("Play", sf::Color::Red, 20, sf::Vector2f(width / 2, (height / 4) * 2)));
menuText.push_back(Text("Quit", sf::Color::White, 20, sf::Vector2f(width / 2, (height / 4) * 3)));
selectedItemIndex = 0;
}
void Menu::setFont(sf::Font& font) {
for (int i = 0; i < menuText.size(); i++) {
menuText[i].setFont(font);
}
menuTitle.setFont(font);
}
void Menu::MoveUp(){
if (selectedItemIndex - 1 >= 0) {
menuText[selectedItemIndex].setFillColor(sf::Color::White);
selectedItemIndex--;
menuText[selectedItemIndex].setFillColor(sf::Color::Red);
}
}
void Menu::MoveDown() {
if (selectedItemIndex + 1 <= (menuText.size()-1)) {
menuText[selectedItemIndex].setFillColor(sf::Color::White);
selectedItemIndex++;
menuText[selectedItemIndex].setFillColor(sf::Color::Red);
}
}
int Menu::ReturnSelectedItemIndex() {
return selectedItemIndex;
}
void Menu::draw(sf::RenderWindow &window) {
window.clear();
for (int i = 0; i < menuText.size(); i++) {
window.draw(menuText[i]);
}
window.draw(menuTitle);
}