Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <SFML/Graphics.hpp>
- #include <SFML/Window.hpp>
- #include <vector>
- using namespace std;
- sf::RectangleShape player_squares[4];
- sf::Vector2f gravity(0, 100);
- sf::Vector2f second_gravity(0, 5);
- int timer = 0;
- sf::RectangleShape objects[100];
- void setShape1()
- {
- for (int x = 0; x < 4; x++)
- {
- player_squares[x].setPosition(250 - 50, (x * 100));
- }
- }
- void setShape2()
- {
- }
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(500, 800), "In Development");
- window.setFramerateLimit(70);
- window.setVerticalSyncEnabled(true);
- //Preparations for player_square objects
- for (int x = 0; x < 4; x++)
- {
- player_squares[x].setSize(sf::Vector2f(100, 100));
- player_squares[x].setFillColor(sf::Color::Blue);
- }
- //Preparations for objects
- for (int x = 0; x < 100; x++)
- {
- objects[x].setSize(sf::Vector2f(100, 100));
- objects[x].setFillColor(sf::Color::Red);
- }
- //Time handling
- sf::Time time = sf::seconds(0);
- sf::Clock clock; //Start the essential clock.
- /* ---TESTING SPECIMEN SECTION--- */
- setShape1();
- objects[4].setPosition(200, 500);
- objects[88].setPosition(100, 300);
- objects[80].setPosition(200, 200);
- sf::Event event;
- while (window.isOpen())
- {
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- window.clear(sf::Color::White); //Clear
- //Check if the player squares are exceeding window height limit or touching another object and stop it
- for (int x = 0; x < 4; x++)
- {
- if (player_squares[x].getPosition().y + 100 >= 800)
- gravity.y = 0;
- }
- /*EXPERIENCING A BUG HERE CHECK IT OUT AND FIX IT*/
- if (player_squares[4].getGlobalBounds().intersects(objects[4].getGlobalBounds())) //PROBABLY SOME ERROR HERE
- {
- cout << "The player square is touching objects";
- }
- //Draw the player squares
- for (int x = 0; x < 4; x++)
- {
- window.draw(player_squares[x]);
- }
- //Move the player squares
- time = clock.getElapsedTime();
- if (time.asSeconds() > 1)
- {
- for (int x = 0; x < 4; x++)
- {
- player_squares[x].move(gravity);
- }
- clock.restart();
- }
- //Check if the objects are exceeding window height limit or touching another object and stop it
- for (int x = 0; x < 100; x++)
- {
- if (objects[x].getPosition().y + 100 >= 800)
- {
- objects[x].setPosition(objects[x].getPosition().x, 700);
- }
- }
- //Draw the objects
- for (int x = 0; x < 100; x++)
- {
- if (objects[x].getPosition().x == 0 && objects[x].getPosition().x == 0)
- ;
- else
- window.draw(objects[x]);
- }
- //Move objects
- for (int x = 0; x < 100; x++)
- {
- objects[x].move(second_gravity);
- }
- window.display(); //Display
- }
- int pause; cin >> pause; //Pause the program
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement