Updated libstormgames. Fixed death sounds following player. Fixed volume keys in survival mode.
This commit is contained in:
		
							
								
								
									
										39
									
								
								src/death_sound.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/death_sound.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
|  | ||||
| import pygame | ||||
| from libstormgames import * | ||||
| from src.object import Object | ||||
|  | ||||
| class DeathSound(Object): | ||||
|     """Special object that plays enemy death sounds at fixed positions and self-removes.""" | ||||
|      | ||||
|     def __init__(self, x, y, enemyType, sounds): | ||||
|         # Initialize as a static object with the death sound name | ||||
|         deathSoundName = f"{enemyType}_dies" | ||||
|         super().__init__( | ||||
|             x,  | ||||
|             y,  | ||||
|             deathSoundName, | ||||
|             isStatic=True, | ||||
|             isCollectible=False, | ||||
|             isHazard=False | ||||
|         ) | ||||
|          | ||||
|         self.sounds = sounds | ||||
|         self.enemyType = enemyType | ||||
|         self.startTime = pygame.time.get_ticks() | ||||
|          | ||||
|         # Get the duration of the death sound if it exists | ||||
|         if deathSoundName in sounds: | ||||
|             self.soundDuration = sounds[deathSoundName].get_length() * 1000  # Convert to milliseconds | ||||
|         else: | ||||
|             self.soundDuration = 1000  # Default 1 second if sound doesn't exist | ||||
|      | ||||
|     def update(self, currentTime): | ||||
|         """Check if sound has finished playing and mark for removal.""" | ||||
|         if currentTime - self.startTime >= self.soundDuration: | ||||
|             # Sound has finished, deactivate and stop audio | ||||
|             self.isActive = False | ||||
|             if self.channel: | ||||
|                 obj_stop(self.channel) | ||||
|                 self.channel = None | ||||
| @@ -257,10 +257,10 @@ class Enemy(Object): | ||||
|         # Award points | ||||
|         self.level.levelScore += totalPoints | ||||
|  | ||||
|         # Play death sound if available using positional audio | ||||
|         deathSound = f"{self.enemyType}_dies" | ||||
|         if deathSound in self.sounds: | ||||
|             self.channel = obj_play(self.sounds, deathSound, self.level.player.xPos, self.xPos, loop=False) | ||||
|         # Create a DeathSound object to play death sound at fixed position | ||||
|         from src.death_sound import DeathSound | ||||
|         deathSoundObj = DeathSound(self.xPos, self.yPos, self.enemyType, self.sounds) | ||||
|         self.level.objects.append(deathSoundObj) | ||||
|  | ||||
|         # Handle witch-specific drops | ||||
|         if self.enemyType == "witch": | ||||
|   | ||||
| @@ -271,6 +271,15 @@ class Level: | ||||
|                 caught = obj.update(currentTime, self.player) | ||||
|                 if caught: | ||||
|                     return  # Stop if player is dead | ||||
|          | ||||
|         # Update death sound objects | ||||
|         from src.death_sound import DeathSound | ||||
|         for obj in self.objects: | ||||
|             if isinstance(obj, DeathSound): | ||||
|                 obj.update(currentTime) | ||||
|          | ||||
|         # Clean up inactive objects (including finished death sounds) | ||||
|         self.objects = [obj for obj in self.objects if obj.isActive] | ||||
|  | ||||
|         # Update bouncing items | ||||
|         for item in self.bouncing_items[:]:  # Copy list to allow removal | ||||
|   | ||||
		Reference in New Issue
	
	Block a user