Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <iostream>
  3.  
  4. static int y = 1;
  5. static sf::RenderWindow window(sf::VideoMode(500, 500), "Laba 6.1");
  6. static sf::Texture background, watch, sandUp, sandDown, downTexture;
  7. static sf::Sprite backSprite, watchSprite, sandUpSprite, sandDownSprite, downTextureSprite;
  8.  
  9. static void loadTextures() {
  10.     background.loadFromFile("Images/back1.png");
  11.     watch.loadFromFile("Images/watch1.png");
  12.     sandUp.loadFromFile("Images/up.png");
  13.     sandDown.loadFromFile("Images/down.png");
  14.     downTexture.loadFromFile("Images/down3.png");
  15. }
  16.  
  17. static void setTextures() {
  18.     backSprite.setTexture(background);
  19.     watchSprite.setTexture(watch);
  20.     sandUpSprite.setTexture(sandUp);
  21.     sandDownSprite.setTexture(sandDown);
  22.     watchSprite.setPosition(257, 275);
  23.     watchSprite.setOrigin(102, 227);
  24.     sandUpSprite.setPosition(180, 130);
  25.     sandDownSprite.setPosition(178, 480);
  26.     downTextureSprite.setTexture(downTexture);
  27.     downTextureSprite.setPosition(177, 239);
  28. }
  29.  
  30.  
  31. static void moveSand() {
  32.     if (y < 14471) {
  33.         sandUpSprite.setPosition(180, 130 + y * 0.01);
  34.         sandDownSprite.setPosition(178, 480 - y * 0.009);
  35.         y++;
  36.     }
  37.         // y = 14 470
  38.        
  39. }
  40.  
  41.  
  42. int main()
  43. {
  44.     loadTextures();
  45.     setTextures();
  46.  
  47.     while (window.isOpen())
  48.     {  
  49.         sf::Event event;
  50.         while (window.pollEvent(event))
  51.         {
  52.             if (event.type == sf::Event::Closed)
  53.                 window.close();
  54.         }
  55.  
  56.         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter)) {
  57.             moveSand();
  58.         }
  59.  
  60.         window.clear();
  61.         window.draw(backSprite);
  62.         window.draw(sandUpSprite);
  63.         window.draw(downTextureSprite);
  64.         window.draw(sandDownSprite);
  65.         window.draw(watchSprite);
  66.         window.display();
  67.     }
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement