Advertisement
Guest User

Untitled

a guest
May 7th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <iostream>
  3.  
  4.  
  5. int main()
  6. {
  7.     sf::RenderWindow window(sf::VideoMode(640, 480),"test");
  8.  
  9.  
  10.     sf::RectangleShape box;
  11.     box.setSize(sf::Vector2f(32, 32));
  12.  
  13.     sf::Clock timer;
  14.     window.setFramerateLimit(120);
  15.  
  16.     float dt;
  17.     sf::Vector2f vel;
  18.  
  19.  
  20.     while (window.isOpen())
  21.     {
  22.         sf::Event event;
  23.         while (window.pollEvent(event))
  24.         {
  25.             if (event.type == sf::Event::Closed)
  26.                 window.close();
  27.         }
  28.  
  29.         dt = timer.restart().asSeconds();
  30.  
  31.         if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) vel.y = -1;
  32.         if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) vel.x = -1;
  33.         if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) vel.y = 1;
  34.         if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) vel.x = 1;
  35.  
  36.         box.move(vel.x * dt * 100, vel.y * dt * 100);
  37.  
  38.         if (vel.x != 0) vel.x = 0;
  39.         if (vel.y != 0) vel.y = 0;
  40.  
  41.        
  42.    
  43.         window.clear();
  44.         window.draw(box);
  45.         window.display();
  46.  
  47.         std::cout << 1.f/dt << std::endl;
  48.        
  49.        
  50.     }
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement