Here is my code:
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
//Creation
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");
//60 FPS
window.setFramerateLimit(60);
window.setKeyRepeatEnabled(false);
//States for buttons and events
sf::Event event;
bool play= true;
//Vars
int ballXVelocity = 6;
int ballYVelocity = 6;
//Render shapes
sf::CircleShape ball;
ball.setRadius(25);
ball.setPosition(375,275);
ball.setFillColor(sf::Color::Blue);
//Game loop
while(play == true)
{
//EVENTS
while (window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
{
play = false;
}
if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
{
play = false;
}
}
//LOGIC
ball.move(ballXVelocity, ballYVelocity);
if(ball.getPosition().x < 0 || ball.getPosition().x > 750) ballXVelocity = -ballXVelocity;
if(ball.getPosition().y < 0 || ball.getPosition().y > 550) ballYVelocity = -ballYVelocity;
//RENDERING
window.clear();
window.draw(ball);
window.display();
}
//Clean up
window.close();
return 0;
}
I made a ball with x velocity = -6 and y velocity = -6
I want now to increase x and y velocity by 1 every 5 second.
How can I do that?
I hope it's not a dumb question and you understand me.