SHARE
TWEET

Untitled

a guest Jan 24th, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SFML/Graphics.hpp>
  2. #include <SFML/System.hpp>
  3.  
  4. auto main() -> int
  5. {
  6.     sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
  7.  
  8.     sf::CircleShape shape{50.f};
  9.  
  10.     sf::Vector2f position{0, 0};
  11.     shape.setFillColor(sf::Color(100, 250, 50));
  12.    
  13.     while(window.isOpen())
  14.     {
  15.         sf::Event event;
  16.         while(window.pollEvent(event))
  17.         {
  18.             if(event.type == sf::Event::Closed)
  19.             {
  20.                 window.close();
  21.             }
  22.  
  23.             if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
  24.             {
  25.                 position.x -= 10;
  26.             }
  27.             if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
  28.             {
  29.                 position.x += 10;
  30.             }
  31.             if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
  32.             {
  33.                 position.y -= 10;
  34.             }
  35.             if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
  36.             {
  37.                 position.y += 10;
  38.             }
  39.         }
  40.  
  41.         shape.setPosition(position);
  42.        
  43.         window.clear(sf::Color::Black);
  44.         window.draw(shape);
  45.         window.display();
  46.     }
  47.  
  48.     return 0;
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top