游戏可以运行
This commit is contained in:
60
game/wave.py
Normal file
60
game/wave.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from game.enemy import Enemy
|
||||
|
||||
|
||||
WAVE_DATA = [
|
||||
[{"type": "normal", "count": 5, "interval": 1.0}],
|
||||
[{"type": "normal", "count": 8, "interval": 0.8}],
|
||||
[{"type": "normal", "count": 5, "interval": 0.8}, {"type": "fast", "count": 3, "interval": 0.6}],
|
||||
[{"type": "fast", "count": 8, "interval": 0.5}],
|
||||
[{"type": "normal", "count": 5, "interval": 0.6}, {"type": "heavy", "count": 2, "interval": 1.5}, {"type": "boss", "count": 1, "interval": 2.0}],
|
||||
[{"type": "normal", "count": 10, "interval": 0.5}, {"type": "fast", "count": 5, "interval": 0.4}],
|
||||
[{"type": "heavy", "count": 5, "interval": 1.0}, {"type": "fast", "count": 5, "interval": 0.5}],
|
||||
[{"type": "normal", "count": 8, "interval": 0.4}, {"type": "heavy", "count": 3, "interval": 0.8}, {"type": "fast", "count": 6, "interval": 0.4}],
|
||||
[{"type": "heavy", "count": 8, "interval": 0.7}, {"type": "fast", "count": 8, "interval": 0.3}],
|
||||
[{"type": "normal", "count": 10, "interval": 0.3}, {"type": "heavy", "count": 5, "interval": 0.5}, {"type": "fast", "count": 10, "interval": 0.3}, {"type": "boss", "count": 2, "interval": 2.0}],
|
||||
]
|
||||
|
||||
|
||||
class WaveManager:
|
||||
def __init__(self):
|
||||
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(WAVE_DATA):
|
||||
self.all_waves_done = True
|
||||
return False
|
||||
|
||||
self.spawn_queue = []
|
||||
for group in 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
|
||||
|
||||
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.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(WAVE_DATA)
|
||||
Reference in New Issue
Block a user