Some minor cleanup.

This commit is contained in:
Storm Dragon
2025-03-21 20:54:13 -04:00
parent cb69189c8e
commit 87d0764156
16 changed files with 193 additions and 193 deletions

View File

@@ -6,7 +6,7 @@ from src.object import Object
class GraspingHands(Object):
"""A hazard where the ground crumbles beneath the player as undead hands reach up."""
def __init__(self, xRange, y, sounds, delay=1000, crumble_speed=0.065):
super().__init__(
xRange,
@@ -19,7 +19,7 @@ class GraspingHands(Object):
self.sounds = sounds
self.delay = delay # Delay in milliseconds before ground starts crumbling
self.crumble_speed = crumble_speed # How fast the crumbling catches up (tiles per frame)
# State tracking
self.isTriggered = False # Has the player entered the zone?
self.triggerTime = 0 # When did the player enter the zone?
@@ -29,13 +29,13 @@ class GraspingHands(Object):
self.crumbleChannel = None # Channel for the looping crumble sound
self.entryFromRight = False # Which side did player enter from
self.crumbleDirection = 1 # Direction the crumbling moves (1=right, -1=left)
def trigger(self, currentTime, playerX):
"""Trigger the grasping hands when player enters range"""
if not self.isTriggered:
self.isTriggered = True
self.triggerTime = currentTime
# Determine which side player entered from
if playerX > (self.xRange[0] + self.xRange[1]) / 2:
# Player entered from right side
@@ -47,48 +47,48 @@ class GraspingHands(Object):
self.entryFromRight = False
self.crumblePosition = self.xRange[0] # Start crumbling from left boundary
self.crumbleDirection = 1 # Crumble moves right
self.isReset = False
# Play initial warning sound
play_sound(self.sounds['grasping_hands_start'])
speak("The ground crumbles as the dead reach for you.")
def reset(self):
"""Reset the trap when player leaves the range"""
if not self.isReset:
self.isTriggered = False
self.crumblePosition = 0
self.isReset = True
# Stop the looping crumble sound if it's playing
if self.crumbleChannel:
obj_stop(self.crumbleChannel)
self.crumbleChannel = None
# Play the end sound
play_sound(self.sounds['grasping_hands_end'])
def update(self, currentTime, player):
"""Update the grasping hands trap state"""
if not self.isActive:
return False
# Check if player is in range
isInRange = self.xRange[0] <= player.xPos <= self.xRange[1]
# Handle player entering/exiting range
if isInRange and not self.isTriggered:
self.trigger(currentTime, player.xPos)
elif not isInRange and self.isTriggered:
self.reset()
return False
# If triggered and delay has passed, start crumbling
if self.isTriggered and currentTime - self.triggerTime >= self.delay:
# Update crumble position based on direction
self.crumblePosition += self.crumble_speed * self.crumbleDirection
# Manage the looping positional audio for the crumbling ground
if self.crumbleChannel is None or not self.crumbleChannel.get_busy():
# Start the sound if it's not playing
@@ -96,14 +96,14 @@ class GraspingHands(Object):
else:
# Update the sound position
self.crumbleChannel = obj_update(self.crumbleChannel, player.xPos, self.crumblePosition)
# Check if player is caught by crumbling
playerCaught = False
if not player.isJumping:
if (self.crumbleDirection > 0 and player.xPos <= self.crumblePosition) or \
(self.crumbleDirection < 0 and player.xPos >= self.crumblePosition):
playerCaught = True
if playerCaught:
if not player.isInvincible:
# Player is caught - instant death
@@ -111,14 +111,14 @@ class GraspingHands(Object):
if self.crumbleChannel:
obj_stop(self.crumbleChannel)
self.crumbleChannel = None
speak("The hands of the dead drag you down!")
player.set_health(0)
return True
# Player is invincible - no warning needed
return False
def __del__(self):
"""Cleanup when object is destroyed"""
# Ensure sound is stopped when object is destroyed