What is a good way to spawn a wave of enemies in a gradual way. And if there are multiple enemies moving in row, and they bounce off the side, how to make it so that they all have the same trajectorie.
Spawn your enemies with a specific X and Y offset based on your loop’s index.
So for example:
int amountOfEnemies = 15;
int enemiesInARow = 5;
int xOffset = 15;
int yOffset = 15;
for(int i = 0; i < amountOfEnemies; i++){
spawnEnemy(i*xOffset, i+1/enemiesInARow*yOffset);
}
This will spawn 3 rows of enemies, with 5 enemies in each row.
Every enemy will be offset with the xOffset and yOffset based on the for loop’s index variable.
I just wrote this off the top of my head, hopefully I didn’t make any mistakes.
To move a wave of enemies in the same direction all the time (I hope that this is what you meant) you just have to change the direction of all your enemies in the wave if you change the direction of a single enemy. This means that you would need some way of grouping together your wave of enemies.
Well almost but not quite. I want the enemy rows act like a snake. If the first bounces off the wall then the 2nd one will continue until it bounces and then the 3rd continues until it bounces and so on.
Atm i have the line of enemies, they all move with the same direction, from their point of view, so it like a straight line falling down and flipping itself.
Edited
Fixed it, instead of having yOffset depend on the amount of enemies, i made it depend on the velocity vector. Now all of the enemies move like i want. but im getting a problem where the distance between them isnt always constant. after some bounces some of the get left behind a bit.