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>
- using namespace std;
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(800, 600), "In Development");
- window.setFramerateLimit(70);
- window.setVerticalSyncEnabled(true);
- sf::RectangleShape square;
- square.setSize(sf::Vector2f(50, 50));
- square.setFillColor(sf::Color::Blue);
- square.setPosition(400, 300);
- sf::Vector2f velocity(0, 0);
- int jumpSpeed = 10, gravity = 1;
- sf::RectangleShape goalpost;
- goalpost.setSize(sf::Vector2f(10, 10));
- goalpost.setFillColor(sf::Color::Red);
- sf::RectangleShape platforms[3];
- for (int x = 0; x < 3; x++)
- {
- platforms[x].setSize(sf::Vector2f(80, 30));
- platforms[x].setFillColor(sf::Color::Cyan);
- }
- platforms[0].setPosition(100, 200);
- platforms[1].setPosition(200, 300);
- platforms[2].setPosition(400, 400);
- sf::Event event;
- while (window.isOpen())
- {
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
- {
- velocity.y = -jumpSpeed;
- }
- else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
- {
- velocity.x = jumpSpeed;
- }
- else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
- {
- velocity.x = -jumpSpeed;
- }
- else
- {
- velocity.y += gravity;
- velocity.x = 0;
- }
- square.move(velocity);
- if (square.getPosition().y >= 500)
- {
- square.setPosition(square.getPosition().x, 500);
- }
- for (int x = 0; x < 3; x++)
- {
- if (square.getGlobalBounds().intersects(platforms[x].getGlobalBounds()))
- {
- if ((square.getPosition().y) <= platforms[x].getPosition().y)
- {
- square.setPosition(square.getPosition().x, platforms[x].getPosition().y - 50);
- velocity.y = 0;
- }
- }
- else
- {
- ;
- }
- }
- window.clear(sf::Color::White); //Clear
- window.draw(square);
- window.draw(platforms[0]);
- window.draw(platforms[1]);
- window.draw(platforms[2]);
- window.display(); //Display
- }
- int pause; cin >> pause; //Pause the program
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement