Files
wicked-quest/src/coffin.py

65 lines
2.1 KiB
Python

import random
from libstormgames import *
from src.item_types import ItemProperties
from src.object import Object
from src.powerup import PowerUp
class CoffinObject(Object):
def __init__(self, x, y, sounds, level, item="random"):
super().__init__(
x, y, "coffin",
isStatic=True,
isCollectible=False,
isHazard=False
)
self.sounds = sounds
self.level = level
self.isBroken = False
self.dropped_item = None
self.specified_item = item
def hit(self, player_pos):
"""Handle being hit by the player's weapon"""
if not self.isBroken:
self.isBroken = True
play_sound(self.sounds['coffin_shatter'])
self.level.player.stats.update_stat('Coffins broken', 1)
# Stop the ongoing coffin sound
if self.channel:
obj_stop(self.channel)
self.channel = None
# Mark coffin as inactive since it's broken
self.isActive = False
# Determine item to drop
if self.specified_item == "random":
item_type = ItemProperties.get_random_item()
else:
# Validate specified item
if ItemProperties.is_valid_item(self.specified_item):
item_type = self.specified_item
else:
# Fall back to random if invalid item specified
item_type = ItemProperties.get_random_item()
# Create item 1-2 tiles away in random direction
direction = random.choice([-1, 1])
drop_distance = random.randint(1, 2)
drop_x = self.xPos + (direction * drop_distance)
self.dropped_item = PowerUp(
drop_x,
self.yPos,
item_type,
self.sounds,
direction,
self.level.leftBoundary,
self.level.rightBoundary
)
return True
return False