More content added, weapons, coin collecting, basic combat.

This commit is contained in:
Storm Dragon
2025-01-30 19:11:33 -05:00
parent 0d115b2bef
commit 53009373c2
10 changed files with 344 additions and 63 deletions

View File

@@ -1,6 +1,9 @@
from libstormgames import *
class Object:
def __init__(self, xPos, yPos, soundName, isStatic=True, isCollectible=False, isHazard=False):
self.xPos = xPos
def __init__(self, x, yPos, soundName, isStatic=True, isCollectible=False, isHazard=False):
# x can be either a single position or a range [start, end]
self.xRange = [x, x] if isinstance(x, (int, float)) else x
self.yPos = yPos
self.soundName = soundName
self.isStatic = isStatic
@@ -8,3 +11,25 @@ class Object:
self.isHazard = isHazard
self.channel = None # For tracking the sound channel
self.isActive = True
# For collectibles in a range, track which positions have been collected
self.collectedPositions = set()
@property
def xPos(self):
"""Return center of range for audio positioning"""
return (self.xRange[0] + self.xRange[1]) / 2
def is_in_range(self, x):
"""Check if a given x position is within this object's range"""
tolerance = 0.5 # Half a unit tolerance
return (self.xRange[0] - tolerance) <= x <= (self.xRange[1] + tolerance)
def collect_at_position(self, x):
"""Mark a specific position in the range as collected"""
self.collectedPositions.add(x)
# If all positions in range are collected, deactivate the object and stop sound
if len(self.collectedPositions) == int(self.xRange[1] - self.xRange[0] + 1):
self.isActive = False
if self.channel:
obj_stop(self.channel)
self.channel = None