I'm developing something similar to Galaga and I'm not entirely sure how to "manage" the bullets i.e. what data structures/algorithms/approaches to use when rendering them on the screen. Let's forget collision detection for now. The way I'm thinking of implementing this is:
- When the application starts, create an array of bullets. Make sure this is at least as big as the total number of bullets you want to have on the screen at any given time. Initialize all the bullets to some default settings. Also create a list of the bullets that are on the screen at any time. Obviously this will be empty initially.
- When the user shoots, get an element of the array and add it to a list of bullets that are currently rendered.
- When drawing, iterate the list of bullets and render each of them. If a bullet gets out of the screen (say
y > 1.0f) then remove it from the list and reset it to default position.
Is this a sensible approach to the problem? Are there alternatives I should consider?
P.S. This question is language/framework (etc) agnostic, but if you think it makes a difference, I'm using OpenGL ES 2 on Android.