lint and spacing fixes. Also fixed problem with levels not showing up in compiled version (hopefully).

This commit is contained in:
Storm Dragon
2025-09-09 22:02:33 -04:00
parent 949c12f193
commit 21d3cd7788
21 changed files with 540 additions and 584 deletions

View File

@@ -5,17 +5,13 @@ import random
from libstormgames import *
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,
y,
"", # No ambient sound for the skull storm
isStatic=True,
isCollectible=False,
isHazard=False
xRange, y, "", isStatic=True, isCollectible=False, isHazard=False # No ambient sound for the skull storm
)
self.sounds = sounds
self.damage = damage
@@ -37,7 +33,7 @@ class SkullStorm(Object):
inRange = self.xRange[0] <= player.xPos <= self.xRange[1]
if inRange and not self.playerInRange:
# Player just entered range - play the warning sound
play_sound(self.sounds['skull_storm'])
play_sound(self.sounds["skull_storm"])
self.playerInRange = True
elif not inRange and self.playerInRange: # Only speak when actually leaving range
# Player just left range
@@ -46,8 +42,8 @@ class SkullStorm(Object):
# Clear any active skulls when player leaves the range
for skull in self.activeSkulls[:]:
if skull['channel']:
obj_stop(skull['channel'])
if skull["channel"]:
obj_stop(skull["channel"])
self.activeSkulls = [] # Reset the list of active skulls
if not inRange:
@@ -55,29 +51,28 @@ class SkullStorm(Object):
# Update existing skulls
for skull in self.activeSkulls[:]: # Copy list to allow removal
if currentTime >= skull['land_time']:
if currentTime >= skull["land_time"]:
# Skull has landed
self.handle_landing(skull, player)
self.activeSkulls.remove(skull)
else:
# Update falling sound
timeElapsed = currentTime - skull['start_time']
fallProgress = timeElapsed / skull['fall_duration']
timeElapsed = currentTime - skull["start_time"]
fallProgress = timeElapsed / skull["fall_duration"]
currentY = self.yPos * (1 - fallProgress)
skull['channel'] = play_random_falling(
skull["channel"] = play_random_falling(
self.sounds,
'falling_skull',
"falling_skull",
player.xPos,
skull['x'],
skull["x"],
self.yPos,
currentY,
existingChannel=skull['channel']
existingChannel=skull["channel"],
)
# Check if we should spawn a new skull
if (len(self.activeSkulls) < self.maxSkulls and
currentTime - self.lastSkullTime >= self.nextSkullDelay):
if len(self.activeSkulls) < self.maxSkulls and currentTime - self.lastSkullTime >= self.nextSkullDelay:
self.spawn_skull(currentTime)
def spawn_skull(self, currentTime):
@@ -91,11 +86,11 @@ class SkullStorm(Object):
# Create new skull
skull = {
'x': random.uniform(self.xRange[0], self.xRange[1]),
'start_time': currentTime,
'fall_duration': fallDuration,
'land_time': currentTime + fallDuration,
'channel': None
"x": random.uniform(self.xRange[0], self.xRange[1]),
"start_time": currentTime,
"fall_duration": fallDuration,
"land_time": currentTime + fallDuration,
"channel": None,
}
self.activeSkulls.append(skull)
@@ -103,20 +98,18 @@ class SkullStorm(Object):
def handle_landing(self, skull, player):
"""Handle a skull landing."""
# Stop falling sound
if skull['channel']:
obj_stop(skull['channel'])
if skull["channel"]:
obj_stop(skull["channel"])
# Play landing sound with positional audio once
channel = pygame.mixer.find_channel(True) # Find an available channel
if channel:
soundObj = self.sounds['skull_lands']
obj_play(self.sounds, 'skull_lands', player.xPos, skull['x'], loop=False)
soundObj = self.sounds["skull_lands"]
obj_play(self.sounds, "skull_lands", player.xPos, skull["x"], loop=False)
# Check if player was hit
if abs(player.xPos - skull['x']) < 1: # Within 1 tile
if abs(player.xPos - skull["x"]) < 1: # Within 1 tile
if not player.isInvincible:
player.set_health(player.get_health() - self.damage)
self.sounds['player_takes_damage'].play()
self.sounds["player_takes_damage"].play()
speak("Hit by falling skull!")