Some minor cleanup.
This commit is contained in:
@@ -7,7 +7,7 @@ from src.object import Object
|
||||
|
||||
class SkullStorm(Object):
|
||||
"""Handles falling skulls within a specified range."""
|
||||
|
||||
|
||||
def __init__(self, xRange, y, sounds, damage, maxSkulls=3, minFreq=2, maxFreq=5):
|
||||
super().__init__(
|
||||
xRange,
|
||||
@@ -22,7 +22,7 @@ class SkullStorm(Object):
|
||||
self.maxSkulls = maxSkulls
|
||||
self.minFreq = minFreq * 1000 # Convert to milliseconds
|
||||
self.maxFreq = maxFreq * 1000
|
||||
|
||||
|
||||
self.activeSkulls = [] # List of currently falling skulls
|
||||
self.lastSkullTime = 0
|
||||
self.nextSkullDelay = random.randint(self.minFreq, self.maxFreq)
|
||||
@@ -32,7 +32,7 @@ class SkullStorm(Object):
|
||||
"""Update all active skulls and potentially spawn new ones."""
|
||||
if not self.isActive:
|
||||
return
|
||||
|
||||
|
||||
# Check if player has entered range
|
||||
inRange = self.xRange[0] <= player.xPos <= self.xRange[1]
|
||||
if inRange and not self.playerInRange:
|
||||
@@ -43,16 +43,16 @@ class SkullStorm(Object):
|
||||
# Player just left range
|
||||
self.playerInRange = False
|
||||
speak("Skull storm ended.")
|
||||
|
||||
|
||||
# Clear any active skulls when player leaves the range
|
||||
for skull in self.activeSkulls[:]:
|
||||
if skull['channel']:
|
||||
obj_stop(skull['channel'])
|
||||
self.activeSkulls = [] # Reset the list of active skulls
|
||||
|
||||
|
||||
if not inRange:
|
||||
return
|
||||
|
||||
|
||||
# Update existing skulls
|
||||
for skull in self.activeSkulls[:]: # Copy list to allow removal
|
||||
if currentTime >= skull['land_time']:
|
||||
@@ -64,7 +64,7 @@ class SkullStorm(Object):
|
||||
timeElapsed = currentTime - skull['start_time']
|
||||
fallProgress = timeElapsed / skull['fall_duration']
|
||||
currentY = self.yPos * (1 - fallProgress)
|
||||
|
||||
|
||||
skull['channel'] = play_random_falling(
|
||||
self.sounds,
|
||||
'falling_skull',
|
||||
@@ -74,21 +74,21 @@ class SkullStorm(Object):
|
||||
currentY,
|
||||
existingChannel=skull['channel']
|
||||
)
|
||||
|
||||
|
||||
# Check if we should spawn a new skull
|
||||
if (len(self.activeSkulls) < self.maxSkulls and
|
||||
currentTime - self.lastSkullTime >= self.nextSkullDelay):
|
||||
self.spawn_skull(currentTime)
|
||||
|
||||
|
||||
def spawn_skull(self, currentTime):
|
||||
"""Spawn a new falling skull at a random position within range."""
|
||||
# Reset timing
|
||||
self.lastSkullTime = currentTime
|
||||
self.nextSkullDelay = random.randint(self.minFreq, self.maxFreq)
|
||||
|
||||
|
||||
# Calculate fall duration based on height (higher = longer fall)
|
||||
fallDuration = self.yPos * 100 # 100ms per unit of height
|
||||
|
||||
|
||||
# Create new skull
|
||||
skull = {
|
||||
'x': random.uniform(self.xRange[0], self.xRange[1]),
|
||||
|
||||
Reference in New Issue
Block a user