Fixed edge of grave warning. Fixed contact sound for weapon.
This commit is contained in:
23
src/level.py
23
src/level.py
@@ -16,6 +16,8 @@ class Level:
|
||||
self.bouncing_items = []
|
||||
self.projectiles = [] # Track active projectiles
|
||||
self.player = Player(levelData["player_start"]["x"], levelData["player_start"]["y"])
|
||||
self.edge_warning_channel = None
|
||||
self.weapon_hit_channel = None
|
||||
|
||||
# Load objects and enemies from level data
|
||||
for obj in levelData["objects"]:
|
||||
@@ -128,9 +130,15 @@ class Level:
|
||||
# Check for enemy hits
|
||||
for enemy in self.enemies:
|
||||
if enemy.isActive and enemy.xPos >= attackRange[0] and enemy.xPos <= attackRange[1]:
|
||||
self.sounds[self.player.currentWeapon.hitSound].play()
|
||||
if self.weapon_hit_channel is None or not self.weapon_hit_channel.get_busy():
|
||||
self.weapon_hit_channel = self.sounds[self.player.currentWeapon.hitSound].play()
|
||||
|
||||
enemy.take_damage(self.player.currentWeapon.damage)
|
||||
|
||||
else:
|
||||
# Reset weapon hit channel when not attacking
|
||||
if self.weapon_hit_channel is not None and not self.weapon_hit_channel.get_busy():
|
||||
self.weapon_hit_channel = None
|
||||
|
||||
# Check for coffin hits - only if we have any coffins
|
||||
for obj in self.objects:
|
||||
if hasattr(obj, 'is_broken'): # Check if it's a coffin without using isinstance
|
||||
@@ -153,9 +161,14 @@ class Level:
|
||||
distance = abs(self.player.xPos - obj.xPos)
|
||||
# Check if within 1 tile and moving
|
||||
|
||||
if distance <= 1 and not self.player.isJumping:
|
||||
# Play edge warning sound (don't need to track the channel)
|
||||
self.sounds['edge'].play()
|
||||
if distance <= 2 and not self.player.isJumping:
|
||||
# Only play edge warning if not already playing
|
||||
if self.edge_warning_channel is None or not self.edge_warning_channel.get_busy():
|
||||
self.edge_warning_channel = self.sounds['edge'].play()
|
||||
|
||||
else:
|
||||
if self.edge_warning_channel is not None and not self.edge_warning_channel.get_busy():
|
||||
self.edge_warning_channel = None
|
||||
|
||||
if obj.is_in_range(self.player.xPos):
|
||||
if obj.isCollectible and self.player.isJumping:
|
||||
|
Reference in New Issue
Block a user