-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainMenu.cpp
92 lines (80 loc) · 2.42 KB
/
mainMenu.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
#include "mainMenu.h"
#include <SFML/Graphics.hpp>
MainMenu::MainMenu()
{
background.loadFromFile("Textures/back.jpg");
backSprite.setTexture(background);
font.loadFromFile("Textures/DK-Lemon-Yellow-Sun.ttf");
title.setFont(font);
title.setString("Chess Game");
title.setCharacterSize(50);
title.setFillColor(sf::Color::White);
title.setPosition(sf::Vector2f(512 / 2, 50));
arrowbg.loadFromFile("Textures/w_king.png");
arrow.setTexture(arrowbg);
arrow.setScale(sf::Vector2f(0.3f, 0.3f));
arrow.setPosition(sf::Vector2f(200, arrpos));
menu[0].setFont(font);
menu[0].setFillColor(sf::Color::White);
menu[selectedMenu].setStyle(sf::Text::Bold);
menu[0].setString("Start Game");
menu[0].setCharacterSize(30);
menu[0].setPosition(sf::Vector2f(512 / 2, 200));
menu[1].setFont(font);
menu[1].setFillColor(sf::Color::White);
menu[1].setString("Recent Match");
menu[1].setCharacterSize(30);
menu[1].setPosition(sf::Vector2f(512 / 2, 250));
menu[2].setFont(font);
menu[2].setFillColor(sf::Color::White);
menu[2].setString("Help");
menu[2].setCharacterSize(30);
menu[2].setPosition(sf::Vector2f(512 / 2, 300));
menu[3].setFont(font);
menu[3].setFillColor(sf::Color::White);
menu[3].setString("Exit");
menu[3].setCharacterSize(30);
menu[3].setPosition(sf::Vector2f(512 / 2, 350));
selectedMenu = 0;
}
MainMenu::~MainMenu()
{
}
void MainMenu::moveDown()
{
if (selectedMenu + 1 < MAX_MAIN_MENU || selectedMenu + 2 < MAX_MAIN_MENU)
{
menu[selectedMenu].setStyle(sf::Text::Regular);
selectedMenu++;
arrpos += 50;
arrpos = std::min(340, arrpos);
arrow.setPosition(sf::Vector2f(200, arrpos));
menu[selectedMenu].setStyle(sf::Text::Bold);
}
}
void MainMenu::moveUp()
{
if (selectedMenu - 1 >= 0 || selectedMenu - 2 >= 0)
{
menu[selectedMenu].setStyle(sf::Text::Regular);
selectedMenu--;
arrpos -= 50;
arrpos = std::max(190, arrpos);
arrow.setPosition(sf::Vector2f(200, arrpos));
menu[selectedMenu].setStyle(sf::Text::Bold);
}
}
int MainMenu::getSelectedMenu()
{
return selectedMenu;
}
void MainMenu::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
target.draw(backSprite);
target.draw(title);
target.draw(arrow);
for (int i = 0; i < MAX_MAIN_MENU; i++)
{
target.draw(menu[i]);
}
}