Advertisement
STANAANDREY

sq_move

Apr 10th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <conio.h>
  3. #include <string>
  4. #include <iostream>
  5. using namespace sf;
  6. using namespace std;
  7. int main()
  8. {
  9.     string s="SFML works!";
  10.     RenderWindow window(VideoMode(520, 520), s);
  11.      RectangleShape player(Vector2f(100.0f,100.0f));
  12.     player.setFillColor(Color::Red);
  13.  
  14.     while (window.isOpen())
  15.     {
  16.       Event ev1;
  17.       while (window.pollEvent(ev1))
  18.       {
  19.           switch (ev1.type) {
  20.       case Event::Closed:
  21.           window.close();break;
  22.           case Event::Resized:
  23.           cout<<ev1.size.width<<endl<<ev1.size.height<<endl;break;
  24.           case Event::TextEntered:
  25.             if (ev1.text.unicode<128)
  26.                 cout<<ev1.text.unicode;
  27.           }
  28.       }
  29.       if (Keyboard::isKeyPressed(Keyboard::Key::A))
  30.           player.move(-0.1f,0.0f);
  31.      else
  32.         if (Keyboard::isKeyPressed(Keyboard::Key::D))
  33.           player.move(0.1f,0.0f);
  34.     else
  35.        if (Keyboard::isKeyPressed(Keyboard::Key::W))
  36.      player.move(0.0f,-0.1f);
  37.      else
  38.         if (Keyboard::isKeyPressed(Keyboard::Key::S))
  39.           player.move(0.0f,0.1f);
  40.  
  41.       window.draw(player);
  42.       window.display();
  43.        window.clear();
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement