- Home /
Defining parameters for a level
For a game that uses waves of enemies in a specific spawn order, spread among 100 levels, what's a good way to store that data and read from it?
Right now I'm using a script I wrote that simply randomizes enemy spawning, speeding up with each new wave, but now I'd like to make it more defined per wave however I'm unfamiliar with this type of game design (defining a level's parameters in text) so I'm not sure where to start…
Should I look into xml files or something of the sort? And how would I structure them? Any help would be appreciated. (If it makes any difference, it's a mobile game.)
Answer by FatWednesday · Sep 07, 2012 at 10:00 PM
Well depending on what kind of definition you want, you may well be able to just use a very simple structure such as the example below.
public struct LevelParams
{
public string LevelName;
public float TimeBetweenWaves;
public int MaxWaves;
public int EnemiesPerWave;
public float TimeBetweenEnemies;
}
That is of course just a very basic and limited method of defining some simple level parameters, you could hard code these in a file, write a custom editor window for creating them, and if you want to, these simple structures would easily save and load to files. This could be with your own custom text serialization, or the very useful XmlSerialization, or a BinaryFormatter depending on what your comfortable with, and what target platform you are going for.
Hope this helps.
Thanks FatWednesday, that helps for sure.
The biggest thing I couldn't get my head around was how to say, "Release three of enemy type1, then a type2 enemy, then five type3 enemies…" etc. But after you listed your examples, I realized I could just create the wave pattern as variables too (e.g., "var numberOfType1")
Thanks for the kick in the right direction!
you're welcome. and yes you can build a small "Wave" structure defining wave parameters, and then build up collections of those for completely custom designed level of waves :). Best of luck in the project.
+1, struct and class are the core of OOP. I'd like to tell everyone new to them to read about the subtle but very significant difference between them. They behave very differently and in most cases, you actually want to use a class, imho.
this is true, I do find myself most of the time using classes, usually for me that's just because I need them to be nullable reference types.