I have worked on this problem for several days. I have almost solved my problem. I have got my sprite to move up and down continuously using the mouse. this done by using the glutTimerFunc function. I want the mouse to get the sprite to move up and down once. I have googled and debugged my code. I have also taken some JavaScript code and ported it over into opengl. let me know if you need my question to be more specific. here is my code so far.
bool onGround = false;
void StartJump()
{
if (onGround)
{
velocityY = -12.0f;
onGround = false;
}
}
void EndJump()
{
if (velocityY < -6.0f)
{
velocityY = -6.0f;
}
}
void Update()
{
velocityY += gravity;
positionY += velocityY;
positionX += velocityX;
if (positionY > 25.0f)
{
positionY = 0.0f;
velocityY = 0.0f;
onGround = false;
}
}
void Loop(int val)
{
Update();
drawSprite();
glutPostRedisplay();
glutTimerFunc(33, Loop, 0);
}
void mouseClicks(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
StartJump();
}
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP)
{
EndJump();
}
}
void handleKeypress(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
case 32:
Loop(0);
break;