Instead of implementing sound changes in one huge go, I'm going to try smaller approaches. Now play_sound has an optional loop parameter set to false by default for backwards compatibility.
This commit is contained in:
		
							
								
								
									
										14
									
								
								sound.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								sound.py
									
									
									
									
									
								
							@@ -80,7 +80,7 @@ class Sound:
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            print(f"Error loading sounds: {e}")
 | 
			
		||||
    
 | 
			
		||||
    def play_sound(self, soundName, volume=1.0):
 | 
			
		||||
    def play_sound(self, soundName, volume=1.0, loop=False):
 | 
			
		||||
        """Play a sound with current volume settings applied.
 | 
			
		||||
        
 | 
			
		||||
        Args:
 | 
			
		||||
@@ -94,7 +94,10 @@ class Sound:
 | 
			
		||||
            return None
 | 
			
		||||
            
 | 
			
		||||
        sound = self.sounds[soundName]
 | 
			
		||||
        channel = sound.play()
 | 
			
		||||
        if loop:
 | 
			
		||||
            channel = sound.play(-1)
 | 
			
		||||
        else:
 | 
			
		||||
            channel = sound.play()
 | 
			
		||||
        if channel:
 | 
			
		||||
            channel.set_volume(volume * self.volumeService.get_sfx_volume())
 | 
			
		||||
        return channel
 | 
			
		||||
@@ -494,7 +497,7 @@ def calculate_volume_and_pan(playerPos, objPos):
 | 
			
		||||
        
 | 
			
		||||
    return volume, left, right
 | 
			
		||||
 | 
			
		||||
def play_sound(sound, volume=1.0):
 | 
			
		||||
def play_sound(sound, volume=1.0, loop=False):
 | 
			
		||||
    """Play a sound with current volume settings applied.
 | 
			
		||||
    
 | 
			
		||||
    Args:
 | 
			
		||||
@@ -504,7 +507,10 @@ def play_sound(sound, volume=1.0):
 | 
			
		||||
    Returns:
 | 
			
		||||
        pygame.mixer.Channel: The channel the sound is playing on
 | 
			
		||||
    """
 | 
			
		||||
    channel = sound.play()
 | 
			
		||||
    if loop:
 | 
			
		||||
        channel = sound.play(-1)
 | 
			
		||||
    else:
 | 
			
		||||
        channel = sound.play()
 | 
			
		||||
    if channel:
 | 
			
		||||
        channel.set_volume(volume * volumeService.get_sfx_volume())
 | 
			
		||||
    return channel
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user