59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from game.enemy import Enemy
|
|
from game.config import PATH_WAYPOINTS
|
|
|
|
|
|
WAVE_DATA = [
|
|
[{"type": "normal", "count": 5, "interval": 1.0}],
|
|
]
|
|
|
|
|
|
class WaveManager:
|
|
def __init__(self, wave_data=None, waypoints=None):
|
|
self.wave_data = wave_data or WAVE_DATA
|
|
self.waypoints = waypoints or PATH_WAYPOINTS
|
|
self.current_wave = 0
|
|
self.spawn_queue = []
|
|
self.spawn_timer = 0
|
|
self.wave_active = False
|
|
self.all_waves_done = False
|
|
|
|
def start_next_wave(self):
|
|
if self.current_wave >= len(self.wave_data):
|
|
self.all_waves_done = True
|
|
return False
|
|
|
|
self.spawn_queue = []
|
|
for group in self.wave_data[self.current_wave]:
|
|
for _ in range(group["count"]):
|
|
self.spawn_queue.append((group["type"], group["interval"]))
|
|
|
|
self.current_wave += 1
|
|
self.wave_active = True
|
|
self.spawn_timer = 0
|
|
return True
|
|
|
|
@property
|
|
def total_waves(self):
|
|
return len(self.wave_data)
|
|
|
|
def update(self, dt, enemies):
|
|
if not self.wave_active:
|
|
return
|
|
|
|
if not self.spawn_queue:
|
|
if all(not e.alive for e in enemies):
|
|
self.wave_active = False
|
|
return
|
|
|
|
self.spawn_timer -= dt
|
|
if self.spawn_timer <= 0:
|
|
enemy_type, interval = self.spawn_queue.pop(0)
|
|
enemies.append(Enemy(enemy_type, self.waypoints))
|
|
self.spawn_timer = self.spawn_queue[0][1] if self.spawn_queue else 0
|
|
|
|
def is_wave_complete(self):
|
|
return not self.wave_active and self.current_wave > 0
|
|
|
|
def has_more_waves(self):
|
|
return self.current_wave < len(self.wave_data)
|