Here''s a snippet of my jump code:
if(KEYDOWN(VK_SPACE))
{
Hero.Setf(JUMPING);
jump = Hero.posY - 30;
};
if(!Hero.Checkf(JUMPING) && Hero.posY < ZERO_LEVEL)
{
Hero.velY += 9.8 * time_mod;
}
else
{
Hero.velY = 0;
};
if(Hero.Checkf(JUMPING) && Hero.posY > jump)
{
Hero.velY += -9.8 * 0.9f;
}
else
{
Hero.Unsetf(JUMPING);
};
Extra details:
Checkf( flag ) returns true if the flag is set to the object
Unsetf( flag ) turns off the object flag
Setf ( flag ) turns on the object flag
The code works fine, the character bounces on command when the user presses the space bar. The problem is that if the space bar is held down or tapped when the player is falling, that object flies up and away

The jump variable is set always 30 units above the player''s position so that even if they are not at ground level they can jump. Can anyone suggest either a new design to this code or just point out a way to fix it so I can''t jump until the object hits the ground?