Trying to create Modular Spawning for a Tower Defense game

Godot Version

4.3.3

Question

I am at the stage where I have to try and create a Modular spawning system for my game where it will detect the level which has been loaded through my SceneManager and it will just take the values in my wave_data array.

I have a general idea on how to implement it but due to the size of the array.

const wave_data1 = {
	"Level01" : [
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
	],
	"Level02" : [
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
	],
	"Level03" : [
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
	],
	"Level04" : [
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
	],
	"Level05" : [
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
		{"Enemies" : {"Beetle" : 10, "Wasp" : 2}, "Time" : 1 },
	],
	
}

This is my array that I have just created and before I continued onwards I wanted to hear some thoughts by some more experienced coders so I learn more even going forwards. If my game for example has around 50 levels and each of those has around 50 or 100 waves for example would that be able to cause an issue with the general spawning or even running of the game?

I plan on creating 3 different SpawnerScripts where each has it’s own purpose. WaveInfo which holds the wave info and extends WaveInfo class. Wave class which extends Waveinfo and holds the Wave information for the current level and the WaveSpawner which extends from the Wave class so they are all interconnected. Would you say my approach is a good one at least?

I agree with the way you save your wave data, but i dont understand the purpose of the three mentioned classes with their inheritance

I tried to make it more modular and for each script to focus on a given task like the WaveInfo to just hold information of the Levels and the Waves, mostly the whole array. The Wave to get information from the WaveInfo and to check for the current Wave and Level and to keep track of those and send the information to the WaveSpawner which will use those to spawn the enemies.
Quite new to Godot and I have been experimenting and learning so I may be doing this the wrong way.

Okay now i understand. I think this is a pretty good system you came up with. An alternative (just so you hear other possibilities, not that its better) would be to just have one component which loads the wave data of the current level from a .txt/.json file and then handles everything in one script. This just comes down to preference

Thank you, haven’t thought about that but will have to look a bit into that to see how it works at least. But I am glad that I am at least not wrong with my way of implementing this system.

1 Like