So I am making a platform shooting game (similar to Contra) and have come across some problems with creating enemy groups. I will try and outline this as clearly as possible:
- Enemies are created only when the player gets to certain points in the frame (so that all enemies and their AI are not on the frame simultaneously)
- Enemies consist of 2 parts. First is an invisible rectangular enemy 'hitbox' that contains the enemy behavior and individual health (the 'hitbox' is the part that essentially is the 'enemy' and physically moves). The second part is the actual enemy graphic that is set to always be on top of the enemy hitbox and follow it.
So during a frame I can easily make it so that when the player gets to certain points the enemies are created and behave properly. The problem is the actual visible enemy graphics that are supposed to be following the invisible enemy hitbox's.
I can make it so that during a frame if I create for example 2 enemy hitboxes as well as 2 of the enemy graphics, then the 2 graphics are indeed properly set to be on top of each hitbox (they don't both overlap on one of the hitboxes). There is still a problem however because the enemy graphics are not individually associated with their respective hitbox, so if I kill one enemy hitbox which in turn destroys the enemy graphic, then BOTH enemy graphics will be destroyed (although the other enemy hitbox will of course still be there)
As some of you may be able to guess, in the code for the enemy hitbox behavior I simply have it so that the enemy graphic position is always set to the hitbox, and when a hitbox is destroyed then the enemy graphic is destroyed.
I could avoid this altogether by making enemies 1 object, but it would be superior to have the hitboxes separate from the enemy graphic which will make the collision detection far better.
So how can I make it so that during a frame if I create a certain number of enemy hitboxes, I also create the same amount of enemy graphics that are individually associated with the enemy hitbox they are following, so that destroying a certain enemy hitbox will only destroy the respective enemy graphic thats following it?
Thanks very much for any help, and let me know if anything needs clarification.