Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <SFML/Window.hpp>
- #include <SFML/Graphics.hpp>
- #include <SFML/Audio.hpp>
- #include <string>
- using namespace std;
- int width = 800;
- int height = 600;
- int mouseX;
- int mouseY;
- int rectangleX = 0;
- int rectangleY = 0;
- bool hovering = false;
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(800, 600), "Generic name for a window");
- sf::Font arial;
- arial.loadFromFile("arial.ttf");
- sf::Text playtext;
- playtext.setFont(arial);
- playtext.setFillColor(sf::Color::Black);
- playtext.setString("PLAY");
- sf::RectangleShape playtext_background;
- playtext_background.setSize(sf::Vector2f(75, 35));
- playtext_background.setFillColor(sf::Color::Red);
- playtext_background.setPosition(rectangleX, rectangleY);
- sf::Event event;
- while (window.isOpen())
- {
- window.clear(sf::Color::White);
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- if (event.type == sf::Event::MouseMoved)
- {
- mouseX = event.mouseMove.x;
- mouseY = event.mouseMove.y;
- }
- if (event.type == sf::Event::MouseButtonPressed)
- {
- if (event.mouseButton.button == sf::Mouse::Left && hovering == true)
- {
- cout << "The player started the game" << endl;
- }
- }
- }
- if (abs(rectangleX - mouseX) < 75)
- {
- if (mouseX < rectangleX)
- ;
- else if (mouseX > rectangleX)
- {
- if (abs(rectangleY - mouseY) < 35)
- {
- playtext_background.setFillColor(sf::Color::Green);
- playtext.setFillColor(sf::Color::Blue);
- hovering = true;
- }
- }
- }
- if(abs(rectangleX - mouseX) > 75 || abs(rectangleY - mouseY) > 35)
- {
- playtext_background.setFillColor(sf::Color::Red);
- playtext.setFillColor(sf::Color::Black);
- hovering = false;
- }
- window.draw(playtext_background);
- window.draw(playtext);
- window.display();
- }
- int pause; cin >> pause; //Pause the program
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement