Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include "menu.h"
  2.  
  3. Menu::Menu(float width, float height)
  4. {
  5. if (!font.loadFromFile("arial.ttf"))
  6. {
  7. //handle error
  8. }
  9. text[0].setFont(font);
  10. text[0].setFillColor(sf::Color::Blue);
  11. text[0].setString("Play");
  12. text[0].setPosition(sf::Vector2f(width / 3, height / (MAX_NUMBER_OF_ITEMS + 1) * 1));
  13.  
  14. text[1].setFont(font);
  15. text[1].setFillColor(sf::Color::White);
  16. text[1].setString("Choose Washing Machine");
  17. text[1].setPosition(sf::Vector2f(width / 3, height / (MAX_NUMBER_OF_ITEMS + 1) * 2));
  18.  
  19. text[2].setFont(font);
  20. text[2].setFillColor(sf::Color::White);
  21. text[2].setString("Scoreboard");
  22. text[2].setPosition(sf::Vector2f(width / 3, height / (MAX_NUMBER_OF_ITEMS + 1) * 3));
  23.  
  24. text[3].setFont(font);
  25. text[3].setFillColor(sf::Color::White);
  26. text[3].setString("Exit Game");
  27. text[3].setPosition(sf::Vector2f(width / 3, height / (MAX_NUMBER_OF_ITEMS + 1) * 4));
  28.  
  29. }
  30.  
  31. Menu::~Menu()
  32. {
  33. }
  34.  
  35. void Menu::draw(sf::RenderWindow & window)
  36. {
  37. for (int i = 0; i < MAX_NUMBER_OF_ITEMS; i++)
  38. {
  39. window.draw(text[i]);
  40. }
  41. }
  42. void Menu::moveUp()
  43. {
  44. if (selectedItemIndex - 1 >= 0)
  45. {
  46. text[selectedItemIndex].setFillColor(sf::Color::White);
  47. selectedItemIndex--;
  48. text[selectedItemIndex].setFillColor(sf::Color::Blue);
  49.  
  50. }
  51. }
  52. void Menu::moveDown()
  53. {
  54. if (selectedItemIndex + 1 < MAX_NUMBER_OF_ITEMS)
  55. {
  56. text[selectedItemIndex].setFillColor(sf::Color::White);
  57. selectedItemIndex++;
  58. text[selectedItemIndex].setFillColor(sf::Color::Blue);
  59. }
  60. }
  61. int Menu::selectedItem()const
  62. {
  63. return this->selectedItemIndex;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement