Advertisement
Guest User

sfml test

a guest
Jul 5th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <iostream>
  3. using namespace sf;
  4. class MainRoom{
  5. public:
  6.     int heightR = 550;
  7.     int widthR  = 550;
  8.     int x,y;
  9.  
  10. };
  11. class Person:public MainRoom{
  12. public:
  13.     int w = 30,h = 4;
  14.  
  15.     int  movePerson(short range);
  16.  
  17. };
  18.  
  19. int Person::movePerson(short range) {
  20.  
  21.     if(Keyboard::isKeyPressed((Keyboard::A))){
  22.  
  23.     }else if(Keyboard::isKeyPressed(((Keyboard::D)))){
  24.  
  25.     }else if(Keyboard::isKeyPressed(((Keyboard::S)))){
  26.  
  27.     }else if(Keyboard::isKeyPressed(((Keyboard::W)))){
  28.  
  29.     }
  30. }
  31.  
  32.  
  33. int main()
  34. {
  35.     //rooom
  36.     MainRoom rm;
  37.     RectangleShape room(Vector2f(rm.widthR, rm.heightR));
  38.     room.setFillColor(Color::Blue);
  39.     //hero
  40.  
  41.     RenderWindow window(VideoMode(600, 600), "SFML works!");
  42.     Person pr;
  43.     CircleShape main_hero(pr.w, pr.h);
  44.     main_hero.setFillColor(Color::Yellow);
  45.  
  46.     while (window.isOpen())
  47.     {
  48.  
  49.         main_hero.move(pr.movePerson(10), 0);
  50.         main_hero.getPosition();
  51.         sf::Event event;
  52.         while (window.pollEvent(event))
  53.         {
  54.             if (event.type == Event::Closed)
  55.                 window.close();
  56.  
  57.         }
  58.         window.clear(Color::Black);
  59.         window.draw(room);
  60.         window.draw(main_hero);
  61.         window.display();
  62.     }
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement