Untitled

 avatar
unknown
plain_text
a year ago
2.7 kB
4
Indexable
#include <SFML/Graphics.hpp>
#include <stdlib.h>
#include <iostream>
#include <chrono>
int main()

{
    sf::RenderWindow window(sf::VideoMode(1920, 1080, 60), "Heat the Angry Loki bobo");
    sf::RectangleShape rectangle(sf::Vector2f(50.f, 50.f));
    rectangle.setSize(sf::Vector2f(800.f, 500.f));
    rectangle.setPosition(600.f, 250.f);
    rectangle.setFillColor(sf::Color(128, 128, 128));
    srand(std::chrono::steady_clock::now().time_since_epoch().count());
    int start = 600;
    int end = 1240;
    int start1 = 250;
    int end1 = 600;
    int x = rand() % (end - start + 1) + start;
    int y = rand() % (end1 - start1 + 1) + start1;
  
    sf::CircleShape shape(70.f);
    shape.setPosition((float)x, (float)y);
    sf::Texture sobaka;
    sobaka.loadFromFile("C:\\Users\\Ulyana\\Desktop\\images\\proekt.png");
    sf::Sprite sobaka228;
    sobaka228.setTexture(sobaka);
    sobaka228.setScale(0.15, 0.15f);
    sobaka228.setPosition((float)x, (float)y);
    sf::Font font;
    font.loadFromFile("C:\\Users\\Ulyana\\Downloads\\Roboto\\Roboto-Black.ttf");
    int Score=0;
    sf::Text score;
    score.setString("Score:  "+std::to_string(Score));
    score.setCharacterSize(50);
    score.setFillColor(sf::Color::Red);
    score.setPosition(100,100);
    score.setFont(font);
   
    
    int t = 100;
    int a = 0;
    while (window.isOpen())
    {
        window.clear();


        window.draw(rectangle);
        score.setString("Score:  " + std::to_string(Score));
        window.draw(score);
        int e = sf::Mouse::getPosition().x;
        int b = sf::Mouse::getPosition().y;
        

        if (t > 0) {
           window.draw(sobaka228);
           t--;
          
        }
        else {
            a += 1; 
            x = rand() % (end - start + 1) + start; 
            y = rand() % (end1 - start1 + 1) + start1; 
            t = 100;
            sobaka228.setPosition((float)x, (float)y);
            
        } 
        
        sf::Event event;
        while (window.pollEvent(event))
        { 
            if (x <= e && e <= x + 800 * 0.15 && y <= b-38 && b-38 <= y + 733 * 0.15 && event.type == sf::Event::MouseButtonPressed){
                Score++;
                a += 1;
                x = rand() % (end - start + 1) + start;
                y = rand() % (end1 - start1 + 1) + start1;
                t = 100;
                sobaka228.setPosition((float)x, (float)y);
            }
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }
        
        window.display();
    }
    return 0;
}
Editor is loading...
Leave a Comment