Friday, February 5, 2010

Aliens must spawn

Only when i tell em, and not before!
I like it when things do as they are told. In this case it is to do with when aliens will spawn onto the lvel and try to kill ya. We need control, some very accurate and designed control in fact. This will be a much different system than the clever dynamic one i used in Pellmell. Even if noone appreciates it, it was a work of Genius. The fact it held up to all those levels and difficulties and variable speed of scrolling. ahh well.

This one is simple, in fact it is about a simple as it can get. We have a time marker and associated with that we have an alien type. This pair will control the spawning of aliens once entered into a linear table. Once one alien has spawned, we will move the index up one notch and wait till the scroll gets to the time (time is really pixel distance along the level), and then spawn the correct alien. So simple a caveman could do it.

However it took me a while in C# as i find the type sytax a bit odd. In C or C++ i would just use pointers and it would have been done in moments. here is the basic tables i used.

// Level Control Data (spawning info)
// 'Time' - is distance down level in pixels you want to spawn the Alien
// 'What' - is the name of what you want to trigger
static int[] L001_Time = { 220, 600, 1000};
static int[] L001_What = { (int)TIDS.WASP, (int)TIDS.BUNGEE, (int)TIDS.FIGHTER};

public static int[][] LevelSpawnData_Time = new int[][] {L001_Time, L001_Time};
public static int[][] LevelSpawnData_What = new int[][] {L001_What, L001_What};

As you can see i defined two simple arrays, Yes, i could have made it a Vector or a small class or typedef with the two elements in it, but it's all about being cheap and fast and cheerful, i just couldn't come up with anything simpler than this. Anyway above you can see that i list the simple int array with the spawn timings in it. Then i have a nice table that links to each of the level int arrays (once i make them). That means i am now able to index through the main table to the levels table and then offset that by an index to work through it.

here is the access line for it.
what = cLevel.LevelSpawnData_What[cLevel.iLevel][iSpawn_Index];

Now that is so simple i love it. So now i have a new spawning control. One anyone can use. I may do an editor, but i am not certain at this point.

No comments:

Post a Comment