Hey SFML Forum, first post here. I've recently gotten into working with SFML so I'm still very new to it. Right now, I'm attempting to work with velocity to make a flappy-bird kind of game.
The issue I'm running into is, well, first I couldn't get the whole "Tap up arrow to flap" kind of thing working, so I decided to go with more of a hold up to go up, release to go down kind of avoider game.
The issue is, I can get my velocity to work when the player is not holding the up key (i.e moving down), but the character slugs along at a velocity of 1 all the while you hold the up key. I know what the problem is, but I can't think of any way to get both up and down working correctly.
What I was thinking was making it so every time you do a key "switch", i.e. going up or going down, it resets your velocity. The issue here is, I can't seem to find somewhere to reset the velocity without it resetting it every loop. Here is the movement part of my code:
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
clock.restart();
up = true;
down = false;
}
if(!sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
up = false;
down = true;
}
if(up == true)
{
graham.move(0,-velocity*acceleration);
velocity = velocity*acceleration;
if(velocity >= 10)
{
velocity = 10;
}
if(velocity > 1)
{
velocity = velocity / 2;
}
}
if(down == true)
{
velocity = velocity*acceleration;
graham.move(0,velocity*acceleration);
if(velocity >= 10)
{
velocity = 10;
}
}
That whole portion of code is located in the while (window.isOpen()), btw.
Thanks in advance for helping me out here. SFML is awesome so far and It's opened up a whole land of possibilities for me!