pbivens67 said:
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.
I think you don't want a bool but a timer to play some explosion animation.
This could be implemented for example like this:
Collision happens: Destroy bug; create explosion and set its time.
Every frame: For each explosion render it's sprite and decrement it's timer. If timer โค 0, delete the explosion.
That's some state management, and eventually you want to move the explosion with the same velocity the bug had when it was hit. Which gives the idea that you could eventually reuse the bug object, but change it to be a explosion from now on and disable it's property to be collideable with other objects, etc.
Or you could implement the explosion using the same classes or components which make up your enemies.
Such design decisions are not easy to make. You may choose an option, but later it turns out there are issues of bad restrictions, or being cumbersome to use, or causing an explosion of code complexity as the game grows, or being inefficient.
This is why many people now use Entity Component Systems after they failed to do it with OOP class hierarchies before. So that's an advanced programming topic.
Looking at your code snippet, it seems you're not ready yet for this, and you are still on a path of failures.
I think so because the renderScene function, and the functions it call do not take any parameters. Instead parameters, you probably use global variables, which is very bad practice because you can not subdivide your program into smaller pieces of functionality and responsibility. Your approach works for very small and simple games, but as complexity grows, it will become unmanageable spaghetti code. At this point you'll give up, start from scratch, but then likely run into the same issues again.
Notice, the path of failures is totally natural, happens to everyone, and is just needed so you can learn from your own mistakes.
But if learning from your own mistakes is not enough, or worse - if you do not even see your mistakes, then you need to learn from other people how to do it right. Look for other peoples small projects of simple games, and pay attention to their overall code structure and how they divide stuff into multiple, smaller systems, each having a clearly defined functionality and responsibility.
And consider to use libraries. You learn nothing from writing sections of glVertex() again and again.
Contrary, you would learn a lot by using sprites, tiled backgrounds, etc., properly implemented in some framework. By using such functionality, you would guess their implementation even without studying the underlying code, and you have more time to work on your game, not just basic low level stuff to draw things, set up alpha blending, etc.
You do this since 15 years? Then your progress is not happening as it should. After 15 years you should know all the answers to the questions you ask here.
Thus, you need to change some things, so the learning and progress finally starts to happen.