More improvements to the override system. Fixed a bug that reared its ugly head during updates to grasping hands code.
This commit is contained in:
		| @@ -6,7 +6,7 @@ import random | |||||||
|  |  | ||||||
|  |  | ||||||
| class Pumpkin: | class Pumpkin: | ||||||
|     def __init__(self, x, isHigh, direction, playerMaxHealth): |     def __init__(self, x, isHigh, direction, playerMaxHealth, soundOverrides=None): | ||||||
|         self.x = x |         self.x = x | ||||||
|         self.isHigh = isHigh |         self.isHigh = isHigh | ||||||
|         self.direction = direction |         self.direction = direction | ||||||
| @@ -14,7 +14,17 @@ class Pumpkin: | |||||||
|         self.isActive = True |         self.isActive = True | ||||||
|         self.damage = playerMaxHealth // 2  # Half of player's max health |         self.damage = playerMaxHealth // 2  # Half of player's max health | ||||||
|         self.soundChannel = None |         self.soundChannel = None | ||||||
|         self.soundName = "pumpkin_low" if isHigh else "pumpkin_high"  # Inverted mapping |  | ||||||
|  |         # Apply sound overrides if provided | ||||||
|  |         if soundOverrides: | ||||||
|  |             if isHigh and "pumpkin_high" in soundOverrides: | ||||||
|  |                 self.soundName = soundOverrides["pumpkin_low"]  # Still inverted for overrides | ||||||
|  |             elif not isHigh and "pumpkin_low" in soundOverrides: | ||||||
|  |                 self.soundName = soundOverrides["pumpkin_high"]  # Still inverted for overrides | ||||||
|  |             else: | ||||||
|  |                 self.soundName = "pumpkin_low" if isHigh else "pumpkin_high"  # Inverted mapping | ||||||
|  |         else: | ||||||
|  |             self.soundName = "pumpkin_low" if isHigh else "pumpkin_high"  # Inverted mapping | ||||||
|  |  | ||||||
|     def update(self, sounds, playerX): |     def update(self, sounds, playerX): | ||||||
|         """Update pumpkin position and sound""" |         """Update pumpkin position and sound""" | ||||||
| @@ -74,6 +84,9 @@ class Catapult(Object): | |||||||
|         self.pendingPumpkin = None  # Store pending pumpkin data |         self.pendingPumpkin = None  # Store pending pumpkin data | ||||||
|         self.pumpkinLaunchTime = 0  # When to launch the pending pumpkin |         self.pumpkinLaunchTime = 0  # When to launch the pending pumpkin | ||||||
|         self.launchSound = "catapult_launch"  # Configurable launch sound |         self.launchSound = "catapult_launch"  # Configurable launch sound | ||||||
|  |         self.soundOverrides = {}  # Store sound overrides for pumpkins | ||||||
|  |         self.activateMessage = "Pumpkin catapult activates!" | ||||||
|  |         self.deactivateMessage = "Out of pumpkin catapult range." | ||||||
|  |  | ||||||
|     def fire(self, currentTime, player): |     def fire(self, currentTime, player): | ||||||
|         """Start the firing sequence""" |         """Start the firing sequence""" | ||||||
| @@ -87,7 +100,7 @@ class Catapult(Object): | |||||||
|         fireDirection = 1 if player.xPos > self.xPos else -1 |         fireDirection = 1 if player.xPos > self.xPos else -1 | ||||||
|  |  | ||||||
|         # Store pumpkin data for later creation |         # Store pumpkin data for later creation | ||||||
|         self.pendingPumpkin = {"isHigh": isHigh, "direction": fireDirection, "playerMaxHealth": player.get_max_health()} |         self.pendingPumpkin = {"isHigh": isHigh, "direction": fireDirection, "playerMaxHealth": player.get_max_health(), "soundOverrides": self.soundOverrides} | ||||||
|  |  | ||||||
|         # Set when to actually launch the pumpkin |         # Set when to actually launch the pumpkin | ||||||
|         self.pumpkinLaunchTime = currentTime + self.launchDelay |         self.pumpkinLaunchTime = currentTime + self.launchDelay | ||||||
| @@ -105,10 +118,10 @@ class Catapult(Object): | |||||||
|         if inRange and not self.isFiring: |         if inRange and not self.isFiring: | ||||||
|             self.isFiring = True |             self.isFiring = True | ||||||
|             self.lastFireTime = currentTime  # Reset timer when entering range |             self.lastFireTime = currentTime  # Reset timer when entering range | ||||||
|             speak("Pumpkin catapult activates!") |             speak(self.activateMessage) | ||||||
|         elif not inRange and self.isFiring: |         elif not inRange and self.isFiring: | ||||||
|             self.isFiring = False |             self.isFiring = False | ||||||
|             speak("Out of pumpkin catapult range.") |             speak(self.deactivateMessage) | ||||||
|  |  | ||||||
|         # Check for pending pumpkin launch |         # Check for pending pumpkin launch | ||||||
|         if self.pendingPumpkin and currentTime >= self.pumpkinLaunchTime: |         if self.pendingPumpkin and currentTime >= self.pumpkinLaunchTime: | ||||||
| @@ -118,6 +131,7 @@ class Catapult(Object): | |||||||
|                 self.pendingPumpkin["isHigh"], |                 self.pendingPumpkin["isHigh"], | ||||||
|                 self.pendingPumpkin["direction"], |                 self.pendingPumpkin["direction"], | ||||||
|                 self.pendingPumpkin["playerMaxHealth"], |                 self.pendingPumpkin["playerMaxHealth"], | ||||||
|  |                 self.pendingPumpkin["soundOverrides"], | ||||||
|             ) |             ) | ||||||
|             self.activePumpkins.append(pumpkin) |             self.activePumpkins.append(pumpkin) | ||||||
|             self.pendingPumpkin = None |             self.pendingPumpkin = None | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ class GraspingHands(Object): | |||||||
|         super().__init__( |         super().__init__( | ||||||
|             xRange, |             xRange, | ||||||
|             y, |             y, | ||||||
|             "grasping_hands",  # Set base sound name for override system |             "",  # No automatic sound - grasping hands manages its own audio | ||||||
|             isStatic=True, |             isStatic=True, | ||||||
|             isCollectible=False, |             isCollectible=False, | ||||||
|             isHazard=True, |             isHazard=True, | ||||||
|   | |||||||
							
								
								
									
										33
									
								
								src/level.py
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								src/level.py
									
									
									
									
									
								
							| @@ -606,13 +606,38 @@ class Level: | |||||||
|     def _apply_object_sound_overrides(self, obj, soundOverrides): |     def _apply_object_sound_overrides(self, obj, soundOverrides): | ||||||
|         """Apply sound overrides to an object based on level pack theme.""" |         """Apply sound overrides to an object based on level pack theme.""" | ||||||
|         # Override base sound name if specified (originalSoundName remains unchanged for game logic) |         # Override base sound name if specified (originalSoundName remains unchanged for game logic) | ||||||
|         if "base" in soundOverrides: |         # Skip for grasping hands since they manage their own audio | ||||||
|             obj.soundName = soundOverrides["base"] |         if "base" in soundOverrides and not hasattr(obj, 'soundPrefix'): | ||||||
|  |             # Check if override sound exists, fall back to original if not | ||||||
|  |             if soundOverrides["base"] in self.sounds: | ||||||
|  |                 obj.soundName = soundOverrides["base"] | ||||||
|  |             # If override doesn't exist, keep original sound (no change needed) | ||||||
|  |  | ||||||
|         # Handle special object-specific overrides |         # Handle special object-specific overrides | ||||||
|         # For catapults, check for launch sound override |         # For catapults, check for launch sound override and pumpkin sound overrides | ||||||
|         if hasattr(obj, 'launchSound') and "launch" in soundOverrides: |         if hasattr(obj, 'launchSound') and "launch" in soundOverrides: | ||||||
|             obj.launchSound = soundOverrides["launch"] |             # Check if override sound exists, fall back to original if not | ||||||
|  |             if soundOverrides["launch"] in self.sounds: | ||||||
|  |                 obj.launchSound = soundOverrides["launch"] | ||||||
|  |  | ||||||
|  |         # Store pumpkin sound overrides in catapult (only store sounds that exist) | ||||||
|  |         if hasattr(obj, 'soundOverrides'): | ||||||
|  |             # Filter out non-existent sounds from pumpkin overrides | ||||||
|  |             filteredOverrides = {} | ||||||
|  |             for key, value in soundOverrides.items(): | ||||||
|  |                 if key in ['pumpkin_low', 'pumpkin_high']: | ||||||
|  |                     if value in self.sounds: | ||||||
|  |                         filteredOverrides[key] = value | ||||||
|  |                 else: | ||||||
|  |                     # Keep non-sound overrides (messages, etc.) | ||||||
|  |                     filteredOverrides[key] = value | ||||||
|  |             obj.soundOverrides = filteredOverrides | ||||||
|  |  | ||||||
|  |         # Apply message overrides for catapults | ||||||
|  |         if hasattr(obj, 'activateMessage') and "activate_message" in soundOverrides: | ||||||
|  |             obj.activateMessage = soundOverrides["activate_message"] | ||||||
|  |         if hasattr(obj, 'deactivateMessage') and "deactivate_message" in soundOverrides: | ||||||
|  |             obj.deactivateMessage = soundOverrides["deactivate_message"] | ||||||
|  |  | ||||||
|         # For grasping hands, check for message overrides and sound prefix override |         # For grasping hands, check for message overrides and sound prefix override | ||||||
|         if hasattr(obj, 'warningMessage') and "warning_message" in soundOverrides: |         if hasattr(obj, 'warningMessage') and "warning_message" in soundOverrides: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user