I'm trying to create a shmup in pygame. Instead of cluttering the level with calling enemies I want to delegate that to another class called Wave. When I want to create one object during a while loop I create a switch that starts True and becomes False after the object is called. When I do this with sprites that are assigned to groups this works, but with a custom class it doesn't.
Here is some pseudocode:
if self.wave_switch0 == True:
wave = Wave()
self.wave_switch0 = False
wave.run()
I tried creating a list and appending the wave, but this doesn't work.
waves = []
if self.wave_switch0 == True:
wave = Wave()
waves.append(wave)
self.wave_switch0 = False
for wave in waves:
wave.run()
Declaring the variable earlier in the code and assigning the value in the if-statement also doesn't work.
self.wave = None
if self.wave_switch0 == True:
wave = Wave()
self.wave_switch0 = False
wave.run()
Is there a way to keep the variable, while also using the switch so the wave isn't constantly being called? Or is there a better way to create an object only once during a while loop?