Enemy Plane and related Instancing
|
This week I have been focusing on compressing all enemy-related code, like collision, shooting and so on, into class specific functions, to allow more enemies to be generated, and to more easily adjust things like how and at what rate enemies fire bullets… ![]()
I started out by taking into account what functions each Enemy needed to have run, and how it would react to functions that the player has, such as the players potato projectiles, as well drawing all sprites created from functions if necessary:
Along the way I was met with a multitude of issues: First of all, I found it close to impossible to use vectors to handle enemy bullets; it would have been useful on paper, as vectors do not have pre-determined size, each enemy could generate a variable amount of bullets… the problem was that by the time bullets collided or just passed their lifetime, they would be deleted and removed from the vector, leading to the vector checking empty positions during iteration, causing the game to crash. I figured that each enemy wouldn’t need more than about 10 bullets on screen at a time anyway, so a normal array should work, but it was more difficult iterating through it without using multiple variables to keep track of the process. I got the process of iterating through enemies and their functions to work smoothly, but I might add that first I used the c++ auto iterator, but this slowed down the game considerably. After using for-loops to iterate through the Enemy vector speed framerate was much less impacted.
|
