Advertisement
Ahmed_Negm

Untitled

Nov 1st, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <bits/stdc++.h>
  3. using namespace sf;
  4. using namespace std;
  5.  
  6. int main(){
  7.      RenderWindow renderWindow(sf::VideoMode(800, 500), "SFML works!");
  8.         Event event;
  9.         Color color(Color::White);
  10.         srand(time(NULL));
  11.         Font font;
  12.         if(!font.loadFromFile("fonts/try.otf")){
  13.             cout<<"not found"<<endl;
  14.             return 0;
  15.         }
  16.  
  17.         Text text;
  18.         text.setFont(font);
  19.         text.setString("Dead Nine!");
  20.         text.setCharacterSize(48);
  21.         Texture texture;
  22.         text.setColor(Color::Black);
  23.         if(!texture.loadFromFile("tmp/try.gif")){
  24.             cout<<"not found"<<endl;
  25.             return 0;
  26.         }
  27.         Sprite s;
  28.         s.setTexture(texture);
  29.         s.setPosition(300,120);
  30.         s.setScale(1.5,1.5);
  31.  
  32.         srand(time(NULL));
  33.         while(renderWindow.isOpen()){
  34.             while(renderWindow.pollEvent(event)){
  35.                 if(event.type == Event::Closed) renderWindow.close();
  36.                 if(Keyboard::isKeyPressed(Keyboard::Up)){
  37.                     s.move(0,-3);
  38.                 }
  39.                 if(Keyboard::isKeyPressed(Keyboard::Right)){
  40.                     s.move(3,0);
  41.                 }
  42.                 if(Keyboard::isKeyPressed(Keyboard::Down)){
  43.                     s.move(0,3);
  44.                 }
  45.                 if(Keyboard::isKeyPressed(Keyboard::Left)){
  46.                     s.move(-3,0);
  47.                 }
  48.                 if(Keyboard::isKeyPressed(Keyboard::W)){
  49.                     s.rotate(3);
  50.                 }
  51.                 if(Keyboard::isKeyPressed(Keyboard::S)){
  52.                     s.rotate(-3);
  53.                 }
  54.                 if(Keyboard::isKeyPressed(Keyboard::Num1)){
  55.                     text.setFillColor(Color(rand()%255,rand()%255,rand()%255));
  56.                 }
  57.                 if(Keyboard::isKeyPressed(Keyboard::Num2)){
  58.                     color = Color(rand()%255,rand()%255,rand()%255);
  59.                 }
  60.  
  61.  
  62.             }
  63.             renderWindow.clear(color);
  64.             renderWindow.draw(s);
  65.             renderWindow.draw(text);
  66.             renderWindow.display();
  67.  
  68.         }
  69.  
  70.    return 0;
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement