Extra life added, fixed sounds to use the new functions for volume control Other various improvements.

This commit is contained in:
Storm Dragon
2025-02-04 07:12:12 -05:00
parent 4f7f5504d1
commit 883dafaac0
9 changed files with 61 additions and 34 deletions

View File

@@ -181,20 +181,23 @@ class Level:
# Check for item collection
if abs(item.xPos - self.player.xPos) < 1 and self.player.isJumping:
self.sounds[f'get_{item.soundName}'].play()
play_sound(self.sounds[f'get_{item.soundName}'])
item.apply_effect(self.player)
item.isActive = False
self.bouncing_items.remove(item)
def handle_combat(self, currentTime):
"""Handle combat interactions between player and enemies"""
attackRange = self.player.get_attack_range(currentTime)
if attackRange:
# Only get attack range if attack is active
if self.player.currentWeapon and self.player.currentWeapon.is_attack_active(currentTime):
attackRange = self.player.currentWeapon.get_attack_range(self.player.xPos, self.player.facingRight)
# Check for enemy hits
for enemy in self.enemies:
if enemy.isActive and enemy.xPos >= attackRange[0] and enemy.xPos <= attackRange[1]:
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()
self.weapon_hit_channel = play_sound(self.sounds[self.player.currentWeapon.hitSound])
enemy.take_damage(self.player.currentWeapon.damage)
else:
@@ -230,7 +233,7 @@ class Level:
distance = abs(self.player.xPos - obj.xPos)
if distance <= 2 and not self.player.isJumping:
if self.edge_warning_channel is None or not self.edge_warning_channel.get_busy():
self.edge_warning_channel = self.sounds['edge'].play()
self.edge_warning_channel = play_sound(self.sounds['edge'])
else:
if self.edge_warning_channel is not None and not self.edge_warning_channel.get_busy():
self.edge_warning_channel = None
@@ -239,16 +242,31 @@ class Level:
if obj.isCollectible and self.player.isJumping:
currentPos = round(self.player.xPos)
if currentPos not in obj.collectedPositions:
self.sounds[f'get_{obj.soundName}'].play()
play_sound(self.sounds[f'get_{obj.soundName}'])
obj.collect_at_position(currentPos)
self.player.collectedItems.append(obj.soundName)
self.player.stats.update_stat('Items collected', 1)
if obj.soundName == "coin":
self.player._coins += 1
self.player.stats.update_stat('Bone dust', 1)
if self.player._coins % 5 == 0:
# Only heal if below max health
if self.player.get_health() < self.player.get_max_health():
self.player.set_health(min(
self.player.get_health() + 1,
self.player.get_max_health()
))
if self.player._coins % 100 == 0:
# Extra life
speak("Extra life")
self.player._coins = 0
self.player._lives += 1
play_sound(self.sounds['extra_life'])
elif obj.isHazard and not self.player.isJumping:
if not self.player.isInvincible:
self.sounds[obj.soundName].play()
play_sound(self.sounds[obj.soundName])
speak("You fell in an open grave!")
self.player.set_health(0)
return False
@@ -269,7 +287,7 @@ class Level:
if self.player.xPos >= obj.xPos:
# Stop all current sounds and play end level sound
pygame.mixer.stop()
self.sounds["end_of_level"].play()
play_sound(self.sounds['end_of_level'])
return True
return False
@@ -289,9 +307,7 @@ class Level:
# 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)
obj_play(self.sounds, 'pumpkin_splat', self.player.xPos, proj.x, loop=False)
break
def throw_projectile(self):
@@ -307,4 +323,4 @@ class Level:
proj_info['direction']
))
# Play throw sound
self.sounds['throw_jack_o_lantern'].play()
play_sound(self.sounds['throw_jack_o_lantern'])