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:
Storm Dragon
2025-09-21 00:17:25 -04:00
parent befc6bbe92
commit ed764cdfdf
3 changed files with 49 additions and 10 deletions

View File

@@ -6,7 +6,7 @@ import random
class Pumpkin:
def __init__(self, x, isHigh, direction, playerMaxHealth):
def __init__(self, x, isHigh, direction, playerMaxHealth, soundOverrides=None):
self.x = x
self.isHigh = isHigh
self.direction = direction
@@ -14,7 +14,17 @@ class Pumpkin:
self.isActive = True
self.damage = playerMaxHealth // 2 # Half of player's max health
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):
"""Update pumpkin position and sound"""
@@ -74,6 +84,9 @@ class Catapult(Object):
self.pendingPumpkin = None # Store pending pumpkin data
self.pumpkinLaunchTime = 0 # When to launch the pending pumpkin
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):
"""Start the firing sequence"""
@@ -87,7 +100,7 @@ class Catapult(Object):
fireDirection = 1 if player.xPos > self.xPos else -1
# 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
self.pumpkinLaunchTime = currentTime + self.launchDelay
@@ -105,10 +118,10 @@ class Catapult(Object):
if inRange and not self.isFiring:
self.isFiring = True
self.lastFireTime = currentTime # Reset timer when entering range
speak("Pumpkin catapult activates!")
speak(self.activateMessage)
elif not inRange and self.isFiring:
self.isFiring = False
speak("Out of pumpkin catapult range.")
speak(self.deactivateMessage)
# Check for pending pumpkin launch
if self.pendingPumpkin and currentTime >= self.pumpkinLaunchTime:
@@ -118,6 +131,7 @@ class Catapult(Object):
self.pendingPumpkin["isHigh"],
self.pendingPumpkin["direction"],
self.pendingPumpkin["playerMaxHealth"],
self.pendingPumpkin["soundOverrides"],
)
self.activePumpkins.append(pumpkin)
self.pendingPumpkin = None