Tower Defence waves loading

Hey guys!

Since I’m not the first guy in history to program a Tower Defence, I thought I might ask you how you solved this, or would have solved it:

Loading waves in a reusable manner. I really don’t want to have to reload a file, or reprocess anything really. I’d like to be able to load and process the data, and then use it several times.

What I thought I’d do, was to interpret some simple simple text-document that feeds a Queue of creeps. This Queue will then be used to grab a Creep, and insert it into the world - thus, creating a wave of Creeps.

There’s a problem here, though. I can’t modify the original Queue, because that would ruin any playthroughs of the same level. I only want to have a single loading screen.

So… how would you solve this?

How about randomized spawns? Make a spawner helper class with variables like: enemy types, spawn delay, max enemies spawned etc. Logic behind that is self-explanatory and those values can vary over time and/or wave.

int wave = 1;

void spawn1(Idk idk){
idk.spawnEnemy(4);
}
void spawn2(Idk idk){
idk.spawnEnemy(6)
}

ArrayList enemys = new ArrayList();
void spawnEnemy(int size){
for(int i = 0; i<size;i++;){

enemys.add(new Enemy(idk,idk,idk,idk,))

}
}

void check(){
if(enemy.isEmpty()){
swich(wave)
case1:
spawn1(Idk);
case2:
spawn2(idk)
}
}

and so one do you get it ???

I’ve never made a tower defence game, but I do have some idea on how to do this.

A good and easy way to load and save data from java is using the json format, which is text based so you can edit the text files outside the game. Reading and writing is typically done using a library, for example Google offers gson, which is an easy to use one.

Now for the data you would need to save. I would create a simple Java class Wave containing the basic information about a wave, e.g. number of creeps of a certain type and the interval between creeps appearing. For example:

public class Wave {

	int numberOfCreeps;
	int creepType;
	float intervalBetweenCreeps;

	public int getNumberOfCreeps() {
		return numberOfCreeps;
	}

	public void setNumberOfCreeps(int numberOfCreeps) {
		this.numberOfCreeps = numberOfCreeps;
	}

	public int getCreepType() {
		return creepType;
	}

	public void setCreepType(int creepType) {
		this.creepType = creepType;
	}

	public float getIntervalBetweenCreeps() {
		return intervalBetweenCreeps;
	}

	public void setIntervalBetweenCreeps(float intervalBetweenCreeps) {
		this.intervalBetweenCreeps = intervalBetweenCreeps;
	}
}

A text file containing a List of Waves would then look like:

[
	{
		"numberOfCreeps":10,
		"creepType":1,
		"intervalBetweenCreeps":0.25
	},
	{
		"numberOfCreeps":10,
		"creepType":1,
		"intervalBetweenCreeps":0.25
	}
]

You can read this from disk by reading a simple text file in the the json format, and converting it into a Java object through the use of gson.

Anyway, this is how I would probably get started.