Updated libstormgames submodule. Added skull storms. Fixed no jack-o-lanterns reported when there actually were. Fixed player being recreated on each new level thus resetting all stats.
This commit is contained in:
63
src/level.py
63
src/level.py
@@ -8,15 +8,17 @@ from src.object import Object
|
||||
from src.player import Player
|
||||
from src.projectile import Projectile
|
||||
from src.powerup import PowerUp
|
||||
from src.skull_storm import SkullStorm
|
||||
|
||||
|
||||
class Level:
|
||||
def __init__(self, levelData, sounds):
|
||||
def __init__(self, levelData, sounds, player):
|
||||
self.sounds = sounds
|
||||
self.objects = []
|
||||
self.enemies = []
|
||||
self.bouncing_items = []
|
||||
self.projectiles = [] # Track active projectiles
|
||||
self.player = Player(levelData["player_start"]["x"], levelData["player_start"]["y"], sounds)
|
||||
self.player = player
|
||||
self.edge_warning_channel = None
|
||||
self.weapon_hit_channel = None
|
||||
self.leftBoundary = levelData["boundaries"]["left"]
|
||||
@@ -53,6 +55,18 @@ class Level:
|
||||
firingRange=obj.get("range", 20)
|
||||
)
|
||||
self.objects.append(catapult)
|
||||
# Check if this is a skull storm
|
||||
elif obj.get("type") == "skull_storm":
|
||||
skullStorm = SkullStorm(
|
||||
xPos,
|
||||
obj["y"],
|
||||
self.sounds,
|
||||
obj.get("damage", 5),
|
||||
obj.get("maximum_skulls", 3),
|
||||
obj.get("frequency", {}).get("min", 2),
|
||||
obj.get("frequency", {}).get("max", 5)
|
||||
)
|
||||
self.objects.append(skullStorm)
|
||||
# Check if this is a coffin
|
||||
elif obj.get("type") == "coffin":
|
||||
coffin = CoffinObject(
|
||||
@@ -120,15 +134,13 @@ class Level:
|
||||
speak("A zombie emerges from the grave!")
|
||||
|
||||
# Handle object audio
|
||||
if not obj.isStatic:
|
||||
if obj.channel is None or not obj.channel.get_busy():
|
||||
obj.channel = obj_play(self.sounds, obj.soundName, self.player.xPos, obj.xPos)
|
||||
else:
|
||||
if obj.channel is None:
|
||||
obj.channel = obj_play(self.sounds, obj.soundName, self.player.xPos, obj.xPos)
|
||||
|
||||
if obj.channel is not None:
|
||||
obj.channel = obj_update(obj.channel, self.player.xPos, obj.xPos)
|
||||
elif obj.soundName: # Only try to play sound if soundName is not empty
|
||||
if not obj.isStatic:
|
||||
obj.channel = obj_play(self.sounds, obj.soundName, self.player.xPos, obj.xPos)
|
||||
else:
|
||||
obj.channel = obj_play(self.sounds, obj.soundName, self.player.xPos, obj.xPos)
|
||||
|
||||
# Update enemies
|
||||
for enemy in self.enemies:
|
||||
@@ -147,6 +159,11 @@ class Level:
|
||||
if isinstance(obj, Catapult):
|
||||
obj.update(currentTime, self.player)
|
||||
|
||||
# Update skull storms
|
||||
for obj in self.objects:
|
||||
if isinstance(obj, SkullStorm):
|
||||
obj.update(currentTime, self.player)
|
||||
|
||||
# Update bouncing items
|
||||
for item in self.bouncing_items[:]: # Copy list to allow removal
|
||||
if not item.update(currentTime):
|
||||
@@ -250,23 +267,31 @@ class Level:
|
||||
if not proj.update():
|
||||
self.projectiles.remove(proj)
|
||||
continue
|
||||
|
||||
|
||||
# Check for enemy hits
|
||||
for enemy in self.enemies:
|
||||
if enemy.isActive and abs(proj.x - enemy.xPos) < 1:
|
||||
proj.hit_enemy(enemy)
|
||||
self.projectiles.remove(proj)
|
||||
# Calculate volume and pan for splat sound based on final position
|
||||
volume, left, right = calculate_volume_and_pan(self.player.xPos, proj.x)
|
||||
if volume > 0: # Only play if within audible range
|
||||
channel = self.sounds["pumpkin_splat"].play()
|
||||
if channel:
|
||||
channel.set_volume(volume * left, volume * right)
|
||||
break
|
||||
|
||||
def throw_projectile(self):
|
||||
"""Have player throw a projectile"""
|
||||
proj_info = self.player.throw_projectile()
|
||||
if proj_info:
|
||||
self.projectiles.append(Projectile(
|
||||
proj_info['type'],
|
||||
proj_info['start_x'],
|
||||
proj_info['direction']
|
||||
))
|
||||
# Play throw sound
|
||||
if f"{proj_info['type']}_throw" in self.sounds:
|
||||
self.sounds[f"{proj_info['type']}_throw"].play()
|
||||
if proj_info is None:
|
||||
speak("No jack o'lanterns to throw!")
|
||||
return
|
||||
|
||||
self.projectiles.append(Projectile(
|
||||
proj_info['type'],
|
||||
proj_info['start_x'],
|
||||
proj_info['direction']
|
||||
))
|
||||
# Play throw sound
|
||||
self.sounds['throw_jack_o_lantern'].play()
|
||||
|
Reference in New Issue
Block a user