I am able to draw a bullet at the front of the cannon of my tank sprite. I want the bullet to shoot at the enemy tank in a parabolic arc. I have drawn two tanks that move horizontally along a grassy ground sprite. the tanks are also sprites.
int i = 0;
int animate;
void vec_shoot()
{
vector<float> move_sprite;
for (float x = -14.0f; x <= 14.0f; x += 2.0f)
{
y = (-0.1f*(x*x)) + 20.0f;
move_sprite.push_back(y);
}
y = move_sprite[i];
x += 2.0f;
if (x >= 30.0f)
{
x = 0.0f;
}
i++;
if (i >= 15)
{
i = 0;
animate = 0;
glutIdleFunc(NULL);
}
glutPostRedisplay();
}
void handleKeypress(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
case 32:
drawFireSprite();
drawBulletSprite();
animate = !animate;
if (animate)
{
glutIdleFunc(vec_shoot);
}
else
{
glutIdleFunc(NULL);
}
glutSwapBuffers();
break;