from libstormgames import * class Object: def __init__(self, x, yPos, soundName, isStatic=True, isCollectible=False, isHazard=False, zombieSpawnChance=0): # 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 self.isCollectible = isCollectible self.isHazard = isHazard self.zombieSpawnChance = zombieSpawnChance self.hasSpawned = False 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