Fixed edge of grave warning. Fixed contact sound for weapon.

This commit is contained in:
Storm Dragon
2025-01-31 13:43:03 -05:00
parent fcc2dbf44a
commit ab73ddfdd5

View File

@@ -16,6 +16,8 @@ class Level:
self.bouncing_items = [] self.bouncing_items = []
self.projectiles = [] # Track active projectiles self.projectiles = [] # Track active projectiles
self.player = Player(levelData["player_start"]["x"], levelData["player_start"]["y"]) 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 # Load objects and enemies from level data
for obj in levelData["objects"]: for obj in levelData["objects"]:
@@ -128,9 +130,15 @@ class Level:
# Check for enemy hits # Check for enemy hits
for enemy in self.enemies: for enemy in self.enemies:
if enemy.isActive and enemy.xPos >= attackRange[0] and enemy.xPos <= attackRange[1]: 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) 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 # Check for coffin hits - only if we have any coffins
for obj in self.objects: for obj in self.objects:
if hasattr(obj, 'is_broken'): # Check if it's a coffin without using isinstance 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) distance = abs(self.player.xPos - obj.xPos)
# Check if within 1 tile and moving # Check if within 1 tile and moving
if distance <= 1 and not self.player.isJumping: if distance <= 2 and not self.player.isJumping:
# Play edge warning sound (don't need to track the channel) # Only play edge warning if not already playing
self.sounds['edge'].play() 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.is_in_range(self.player.xPos):
if obj.isCollectible and self.player.isJumping: if obj.isCollectible and self.player.isJumping: