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;
- int width = 800;
- int height = 600;
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(width, height), "In Development");
- window.setFramerateLimit(70);
- window.setVerticalSyncEnabled(true);
- sf::RectangleShape player; //I WENT IN AND CHANGED A BIT OF THE CODE IN THIS CLASS RESTORE IT LATER ON
- player.setPosition(width / 2, height / 2);
- player.setSize(sf::Vector2f(50, 50));
- player.setFillColor(sf::Color::Cyan);
- sf::Vector2f velocity(0, 0);
- float gravity = .4;
- sf::Time time = sf::seconds(0);
- sf::Clock clock;
- bool truth = false;
- bool increase_downward_acceleration = false;
- sf::Event event;
- while (window.isOpen())
- {
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- if (event.type == sf::Event::KeyPressed)
- {
- if (event.key.code == sf::Keyboard::Space)
- {
- if (player.getPosition().y > (height/2) - 200)
- {
- truth = true;
- increase_downward_acceleration = false;
- }
- }
- if (event.key.code == sf::Keyboard::Right)
- {
- velocity.x = 3;
- }
- else if (event.key.code == sf::Keyboard::Left)
- {
- velocity.x = -3;
- }
- }
- }
- //Handle inputs
- if (player.getPosition().y <= (height / 2) - 200)
- {
- increase_downward_acceleration = true;
- truth = false;
- }
- else if (truth == true)
- {
- velocity.y = -7;
- increase_downward_acceleration = false;
- }
- cout << player.getPosition().y << endl;
- if (increase_downward_acceleration)
- velocity.y += gravity;
- if (player.getPosition().y >= (height / 2) + 50 && truth == false)
- {
- velocity.y = 0;
- velocity.x = 0;
- }
- window.clear(sf::Color::White); //Clear
- player.move(velocity);
- window.draw(player);
- window.display(); //Display
- }
- int pause; cin >> pause; //Pause the program
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement