Advertisement
Felanpro

in development

Apr 10th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.07 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <SFML/Graphics.hpp>
  4. #include <SFML/Window.hpp>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. sf::RectangleShape player_squares[4];
  10. sf::Vector2f gravity(0, 100);
  11. sf::Vector2f second_gravity(0, 1);
  12. int timer = 0;
  13.  
  14. sf::RectangleShape objects[100];
  15.  
  16. void setShape1()
  17. {
  18.     for (int x = 0; x < 4; x++)
  19.     {
  20.         player_squares[x].setPosition(250 - 50, (x * 100));
  21.     }
  22. }
  23.  
  24. void setShape2()
  25. {
  26.     for (int x = 0; x < 4; x++)
  27.     {
  28.         player_squares[x].setPosition(100 * x + 100, 100);
  29.     }
  30. }
  31.  
  32. int main()
  33. {
  34.     sf::RenderWindow window(sf::VideoMode(500, 800), "In Development");
  35.     window.setFramerateLimit(70);
  36.     window.setVerticalSyncEnabled(true);
  37.     //Preparations for player_square objects
  38.     for (int x = 0; x < 4; x++)
  39.     {
  40.         player_squares[x].setSize(sf::Vector2f(100, 100));
  41.         player_squares[x].setFillColor(sf::Color::Blue);
  42.     }
  43.  
  44.     //Preparations for objects
  45.     for (int x = 0; x < 100; x++)
  46.     {
  47.         objects[x].setSize(sf::Vector2f(100, 100));
  48.         objects[x].setFillColor(sf::Color::Red);
  49.     }
  50.  
  51.     //Time handling
  52.     sf::Time time = sf::seconds(0);
  53.     sf::Clock clock; //Start the essential clock.
  54.  
  55.     /* ---TESTING SPECIMEN SECTION--- */
  56.     setShape1();
  57.     objects[67].setPosition(200, 700);
  58.  
  59.     sf::Event event;
  60.     while (window.isOpen())
  61.     {
  62.         while (window.pollEvent(event))
  63.         {
  64.             if (event.type == sf::Event::Closed)
  65.                 window.close();
  66.         }
  67.  
  68.         window.clear(sf::Color::White); //Clear
  69.  
  70.         //Check if the player squares are exceeding window height limit or touching another object and stop it
  71.         gravity.y = 100;
  72.         for (int y = 0; y < 100; y++)
  73.         {
  74.             for (int x = 0; x < 4; x++)
  75.             {
  76.                 if (player_squares[x].getPosition().y + 100 >= 800)
  77.                 {
  78.                     gravity.y = 0;
  79.                 }
  80.             }
  81.         }
  82.  
  83.         /*EXPERIENCING A BUG HERE CHECK IT OUT AND FIX IT*/
  84.         bool breaking_bad = false;
  85.         for (int x = 0; x < 4; x++)
  86.         {
  87.             for (int y = 0; y < 100; y++)
  88.             {
  89.                 if (player_squares[x].getPosition().y + 101 == objects[x].getPosition().y)
  90.                 {
  91.                     breaking_bad = true;
  92.                     gravity.y = 0;
  93.                 }
  94.             }
  95.             if (breaking_bad)
  96.             {
  97.                 gravity.y = 0;
  98.                 cout << "The player square is intersecting" << endl;
  99.             }
  100.         }
  101.  
  102.         //Draw the player squares
  103.         for (int x = 0; x < 4; x++)
  104.         {
  105.             window.draw(player_squares[x]);
  106.         }
  107.         //Move the player squares
  108.         time = clock.getElapsedTime();
  109.         if (time.asSeconds() > 1)
  110.         {
  111.             for (int x = 0; x < 4; x++)
  112.             {
  113.                 player_squares[x].move(gravity);
  114.             }
  115.             clock.restart();
  116.         }
  117.  
  118.         //Check if the objects are exceeding window height limit or touching another object and stop it
  119.         for (int x = 0; x < 100; x++)
  120.         {
  121.             if (objects[x].getPosition().y + 100 >= 800)
  122.             {
  123.                 objects[x].setPosition(objects[x].getPosition().x, 700);
  124.             }
  125.         }
  126.  
  127.         //Draw the objects
  128.         for (int x = 0; x < 100; x++)
  129.         {
  130.             if (objects[x].getPosition().x == 0 && objects[x].getPosition().x == 0)
  131.                 ;
  132.             else
  133.                 window.draw(objects[x]);
  134.         }
  135.         //Move objects
  136.         for (int x = 0; x < 100; x++)
  137.         {
  138.             objects[x].move(second_gravity);
  139.         }
  140.  
  141.         window.display(); //Display
  142.     }
  143.  
  144.     int pause; cin >> pause; //Pause the program
  145.     return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement