Advertisement
Felanpro

Array of objects

Apr 6th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <SFML/Graphics.hpp>
  4. #include <SFML/Window.hpp>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     sf::RenderWindow window(sf::VideoMode(800, 600), "Project");
  11.     window.setFramerateLimit(70);
  12.     window.setVerticalSyncEnabled(true);
  13.  
  14.     sf::RectangleShape square[14];
  15.     for (int x = 0; x < 10; x++)
  16.     {
  17.         square[x].setSize(sf::Vector2f(50, 50));
  18.         square[x].setFillColor(sf::Color::Blue);
  19.         square[x].setPosition(x * 50, 0);
  20.     }
  21.  
  22.     sf::Event event;
  23.     while (window.isOpen())
  24.     {
  25.         while (window.pollEvent(event))
  26.         {
  27.             if (event.type == sf::Event::Closed)
  28.                 window.close();
  29.             else if (event.type == sf::Event::KeyPressed)
  30.             {
  31.                 for (int x = 0; x < 10; x++)
  32.                 {
  33.                     square[x].setPosition(square[x].getPosition().x + 3, square[x].getPosition().y);
  34.                 }
  35.             }
  36.         }
  37.  
  38.         for (int x = 0; x < 10; x++)
  39.         {
  40.             if (square[x].getPosition().y + 50 < 600)
  41.                 square[x].setPosition(square[x].getPosition().x, square[x].getPosition().y + 3);
  42.         }
  43.  
  44.         window.clear(sf::Color::White); //Clear
  45.  
  46.         for (int x = 0; x < 10; x++)
  47.             window.draw(square[x]);
  48.  
  49.         window.display(); //Display
  50.     }
  51.  
  52.     int pause; cin >> pause; //Pause the program
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement