'How do i hide the bug image once its hit by a bullet in opengl and c++

I am working on defender/space invaders game.

I have drawn bug sprite and a bullet sprite. I shoot at the bug with a bullet but when the bullet hits the bug it draws a collision sprite which stays on the screen. I want the collision sprite to not be drawn after it is drawn. I am using a boolean to determine what sprite is to be drawn.

here is my code.

void renderScene()
{
    glClear(GL_COLOR_BUFFER_BIT);
    drawShip();
    drawBullet();
    coll_ship_one();
    if (coll == false)
    {
    drawBug_one();
    }
    if (coll == true)
    {
    drawCollision_one();
    }
    glutSwapBuffers();
}


Solution 1:[1]

I have implemented a 3-state bug drawing system, I have used -1 for drawing a bug and 1 for the collision sprite and 0 for not drawing a bug. here is code

void renderScene()
{
    glClear(GL_COLOR_BUFFER_BIT);
    drawShip();
    drawBullet();
    coll_ship_one();
    if (coll == -1)
    {
    drawBug_one();
    }
    if (coll == 1)
    {
    drawCollision_one();
    coll = 0;
    }
    if (coll == 0)
    {
    // no bug
    }
    glutSwapBuffers();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gamer67