well let me explain that my code does when I hit the space bar my sprite moves up to a limit and when I hit the space bar again it moves my sprite down when I keep the space bar down it moves up and down. my question is how do I hit the space bar and get my sprite to move up and down of its own accord, I want it to jump like in video games. I just need a little hint I have almost solved my problem.
void spritejump()
{
if (state == false)
{
if (positionY <= 20.0f)
{
positionY += 5.0f;
}
if (positionY == 20.0f)
{
state = true;
}
}
else if (state == true)
{
if (positionY >= 0.0f)
{
positionY -= 5.0f;
}
if (positionY == 0.0f)
{
state = false;
}
}
}
void handleKeypress(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
case 32:
for (int i = 0; i <= 10; i++)
{
spritejump();
}