1 decade ago by coreysnyder
Let's say I have 10 levels. In each level I have a common "Enemy Spawner" which spits out enemies. I want each level to spawn different enemies at different times. I know how to code the Enemy Spawner, what I don't know about is how you defined level specific variables which get loaded in and are accessible when the level is running.
My idea behind how to do it would be to build a config object of all the enemies I want to spawn for each level. Store them in an array or a hash like:
Then in my init, I'll determine which level I'm on with some built in function I assume exists (share?). Based on the level, I can pull out the enemy config, and pass that to my "Enemy Spawner" using createEntity.
Is that how you'd do things? Is there a better way to store level specific variables?
My idea behind how to do it would be to build a config object of all the enemies I want to spawn for each level. Store them in an array or a hash like:
var enemyArray = [ 0: { 5: "Monster 1" 8: "Monster 1" 10: "Monster 2" }, 0: { .... } ]
Then in my init, I'll determine which level I'm on with some built in function I assume exists (share?). Based on the level, I can pull out the enemy config, and pass that to my "Enemy Spawner" using createEntity.
Is that how you'd do things? Is there a better way to store level specific variables?