Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "menu.h"
- Menu::Menu(float width, float height)
- {
- if (!font.loadFromFile("arial.ttf"))
- {
- //handle error
- }
- text[0].setFont(font);
- text[0].setFillColor(sf::Color::Blue);
- text[0].setString("Play");
- text[0].setPosition(sf::Vector2f(width / 3, height / (MAX_NUMBER_OF_ITEMS + 1) * 1));
- text[1].setFont(font);
- text[1].setFillColor(sf::Color::White);
- text[1].setString("Choose Washing Machine");
- text[1].setPosition(sf::Vector2f(width / 3, height / (MAX_NUMBER_OF_ITEMS + 1) * 2));
- text[2].setFont(font);
- text[2].setFillColor(sf::Color::White);
- text[2].setString("Scoreboard");
- text[2].setPosition(sf::Vector2f(width / 3, height / (MAX_NUMBER_OF_ITEMS + 1) * 3));
- text[3].setFont(font);
- text[3].setFillColor(sf::Color::White);
- text[3].setString("Exit Game");
- text[3].setPosition(sf::Vector2f(width / 3, height / (MAX_NUMBER_OF_ITEMS + 1) * 4));
- }
- Menu::~Menu()
- {
- }
- void Menu::draw(sf::RenderWindow & window)
- {
- for (int i = 0; i < MAX_NUMBER_OF_ITEMS; i++)
- {
- window.draw(text[i]);
- }
- }
- void Menu::moveUp()
- {
- if (selectedItemIndex - 1 >= 0)
- {
- text[selectedItemIndex].setFillColor(sf::Color::White);
- selectedItemIndex--;
- text[selectedItemIndex].setFillColor(sf::Color::Blue);
- }
- }
- void Menu::moveDown()
- {
- if (selectedItemIndex + 1 < MAX_NUMBER_OF_ITEMS)
- {
- text[selectedItemIndex].setFillColor(sf::Color::White);
- selectedItemIndex++;
- text[selectedItemIndex].setFillColor(sf::Color::Blue);
- }
- }
- int Menu::selectedItem()const
- {
- return this->selectedItemIndex;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement