You didn't really implement vertical speed because you change the Y coordinate directly and test the height for "falling down". It's possible but in this case the jump will be always at the same speed which is not realistic. Nevertheless, I give you a solution for this.
At the beginning of the program, we need more variables:
const int GRAVITY = 1;
const int STARTY = 383;
int yPos = STARTY;
int xPos = 100;
int xSpeed = 2;
int jHeight = 0;
bool Jumping = false;
I introduced STARTY because we need to check when the player is back on ground to stop the jump and it's better to check a name then a hardcoded pixel value. And the "Jumping" flag is needed otherwise the sprite would jump only as long as you hold the space key down, which is not realistic either. Instead it should move as long as it is in jumping state. Here is the movement code. I changed the height to 50 because 10 was too small to test with.
while ( LoopGDK ( ) )
{
if(dbSpaceKey() && ! Jumping)
{
Jumping = true;
jHeight = 0;
}
if (Jumping)
{
dbText(340, 240, "JUMPING!");
jHeight += GRAVITY;
if (jHeight < 50) yPos -= GRAVITY;
else yPos += GRAVITY;
if (yPos > STARTY) {
yPos = STARTY;
Jumping = false;
}
}
But this is not really gravity, it is just changing the Y position with a constant amount every loop. With gravity, the vertical speed of the jump is changing: first it's high, then decreases, then becomes negative (start falling) and then falling faster. Here is the implementation with vertical speed. In this, you don't test the height, instead you can change the starting vertical speed to adjust how high you can jump.
Start with the variables again, notice the new ySpeed:
const int GRAVITY = 1;
const int STARTY = 383;
int yPos = STARTY;
int xPos = 100;
int xSpeed = 2;
int ySpeed = 0;
bool Jumping = false;
and the movement:
while ( LoopGDK ( ) )
{
if(dbSpaceKey() && ! Jumping)
{
Jumping = true;
ySpeed = 20;
}
if (Jumping) {
dbText(340, 240, "JUMPING!");
ySpeed -= GRAVITY;
yPos -= ySpeed;
if (yPos > STARTY) {
yPos = STARTY;
Jumping = false;
}
}