Question about Building a level using tables
ookami007
Member Posts: 581
I am making a vertical shooter and unlike most (that randomly spawn enemies), I want to have waves of enemies in a set order.
I'm thinking that having a table that keeps track of when and where to spawn the enemy is the way to go, but I'm not sure how to necessarily kick it off.
Are there any examples anywhere of someone doing this or anyone have any ideas?
I assume that I would have a table for each level with enemy to spawn (enemytype), time to spawn (in seconds) and x,y coordinate.
Any ideas on the most efficient way to do this?
Comments
So, I tried implementing something.
I have a table with the time to spawn, enemy type and x coordinate (they always spawn at the top).
Right now, I have a spawner actor that is checked every .1 seconds. It checks to see if the game timer is greater than or equal to the spawn time in the next row of the table.
If so, it spawns it.
So far, this works OK. Here's the problem.... I want mulitple ships to spawn at the same time - like a formation. So, one at 50,0 another at 150,0 and the 3rd at 200,0. So in my table, have entries like:
spawn time / enemy type / x coor
19, 1, 50
19, 1, 150
19, 1, 200
That SHOULD theoretically put all three in a straight line on the screen. BUT... because of the .1 time difference, they are not.
Is there a better way to check?
What you do is utilize multiple columns. Decide how many creatures you want to spawn at any one time, the maximum, and create a block of code for each column. I see that you appear to use 3 columns, so basically you recreate the spawning code with columns 4, 5, and 6, and then for 7, 8, and 9, and so forth. Then you set it up to do the same action. you can even assign columns to different types of ships, no matter how many variables you need to assign. That way, the game will check all the columns at the same time with the different code blocks and spawn however many are listed. This gives you flexibility for number and precision of spawn time.
Thanks. I'll try that.
One other thought I had was to duplicate my code 6 times, since it will check the next entry and if it has the same time, then it will spawn as well.
Since each successful placement advances the rowcount, then 6 copies would spawn up to 6 enemies... which is all I can reasonably place in a row anyway.
I find the column setup very modular. it means at any time you can spawn 2, 3, 4, or so on enemies per tick. Im not sure how you mean the other option, but whatever works for you best.