Advertisement
Felanpro

Starting menu

Mar 24th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <SFML/Window.hpp>
  4. #include <SFML/Graphics.hpp>
  5. #include <SFML/Audio.hpp>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. int width = 800;
  11. int height = 600;
  12. int mouseX;
  13. int mouseY;
  14. int rectangleX = 0;
  15. int rectangleY = 0;
  16.  
  17. bool hovering = false;
  18.  
  19. int main()
  20. {
  21.     sf::RenderWindow window(sf::VideoMode(800, 600), "Generic name for a window");
  22.  
  23.     sf::Font arial;
  24.     arial.loadFromFile("arial.ttf");
  25.     sf::Text playtext;
  26.     playtext.setFont(arial);
  27.     playtext.setFillColor(sf::Color::Black);
  28.     playtext.setString("PLAY");
  29.  
  30.     sf::RectangleShape playtext_background;
  31.     playtext_background.setSize(sf::Vector2f(75, 35));
  32.     playtext_background.setFillColor(sf::Color::Red);
  33.     playtext_background.setPosition(rectangleX, rectangleY);
  34.  
  35.     sf::Event event;
  36.     while (window.isOpen())
  37.     {
  38.         window.clear(sf::Color::White);
  39.  
  40.         while (window.pollEvent(event))
  41.         {
  42.             if (event.type == sf::Event::Closed)
  43.                 window.close();
  44.  
  45.             if (event.type == sf::Event::MouseMoved)
  46.             {
  47.                 mouseX = event.mouseMove.x;
  48.                 mouseY = event.mouseMove.y;
  49.             }
  50.  
  51.             if (event.type == sf::Event::MouseButtonPressed)
  52.             {
  53.                 if (event.mouseButton.button == sf::Mouse::Left && hovering == true)
  54.                 {
  55.                     cout << "The player started the game" << endl;
  56.                 }
  57.             }
  58.         }
  59.  
  60.         if (abs(rectangleX - mouseX) < 75)
  61.         {
  62.             if (mouseX < rectangleX)
  63.                 ;
  64.             else if (mouseX > rectangleX)
  65.             {
  66.                 if (abs(rectangleY - mouseY) < 35)
  67.                 {
  68.                     playtext_background.setFillColor(sf::Color::Green);
  69.                     playtext.setFillColor(sf::Color::Blue);
  70.                     hovering = true;
  71.                 }
  72.             }
  73.         }
  74.  
  75.         if(abs(rectangleX - mouseX) > 75 || abs(rectangleY - mouseY) > 35)
  76.         {
  77.             playtext_background.setFillColor(sf::Color::Red);
  78.             playtext.setFillColor(sf::Color::Black);
  79.             hovering = false;
  80.         }
  81.  
  82.         window.draw(playtext_background);
  83.         window.draw(playtext);
  84.         window.display();
  85.     }
  86.  
  87.     int pause; cin >> pause; //Pause the program
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement