Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "program.h"
- #include "ball.h"
- Program::Program(int width, int height) : w(width), h(height), window(sf::VideoMode(width, height), "SFML Test"), ball(w/2, h/2)
- {
- }
- int Program::mainLoop()
- {
- sf::Event events;
- sf::Clock clock;
- if (!window.isOpen())
- {
- return EXIT_FAILURE;
- }
- while (window.isOpen())
- {
- while (window.pollEvent(events))
- {
- if (events.type == sf::Event::EventType::Closed)
- {
- window.close();
- }
- eventHandler(events);
- }
- if (clock.getElapsedTime().asSeconds() >= 1.0 / 60.0)
- {
- ball.update();
- clock.restart();
- }
- //clear
- window.clear(sf::Color::Black);
- //Features
- //sf::RectangleShape rectWin(sf::Vector2f(700, 700));
- //rectWin.setPosition((w - 700)/2, (h-700)/2);
- //Draw
- //window.draw(rectWin);
- ball.draw(window);
- //Display
- window.display();
- }
- }
- void Program::eventHandler(sf::Event events)
- {
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))
- {
- ball.setRotSpeed(-0.1);
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D))
- {
- ball.setRotSpeed(0.1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement