well I am still working on my little 2d platformer. I am able to get my dog sprite to jump up onto the first tier. My question is how I get my dog sprite to move to the right instead of staying in the same place when I try to move to the right. I have tried using move_sprite=x line of code to solve my problem.
void count()
{
for (float x = 22.5f; x >= -22.5f; x--)
{
y = (-0.1f * (x * x)) + 50;
parabola.push_back(y);
}
}
void jump()
{
if (state == 0)
{
y = parabola[i];
i++;
}
if (y >= tier_one)
{
state = 1;
}
if (state == 1)
{
y = tier_one;
}
if (state == 0 && direction_x == -1)
{
x--;
}
if (state == 0 && direction_x == 1)
{
x++;
move_sprite = x;
}
glutPostRedisplay();
}
void handleKeypress(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
case 32:
count();
jump();
break;
}
glutPostRedisplay();
}
void handleSpecialKeypress(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_LEFT:
move_sprite--;
if (move_sprite <= -255.0f)
{
move_sprite = -255.0f;
}
direction_x = -1;
break;
case GLUT_KEY_RIGHT:
cout << move_sprite << endl;
if (move_sprite >= 0.0f)
{
move_sprite = 0.0f;
}
move_sprite++;
direction_x = 1;
break;
case GLUT_KEY_UP:
break;
case GLUT_KEY_DOWN:
break;
}
glutPostRedisplay();
}