Code cleanup, added more functionality. Floating coffins that spawn items, graves can spawn zombies, etc.

This commit is contained in:
Storm Dragon
2025-01-30 22:22:59 -05:00
parent 53009373c2
commit 6c000d78d8
10 changed files with 402 additions and 15 deletions

40
src/coffin.py Normal file
View File

@@ -0,0 +1,40 @@
from libstormgames import *
from src.object import Object
from src.powerup import PowerUp
import random
class CoffinObject(Object):
def __init__(self, x, y, sounds):
super().__init__(
x, y, "coffin",
isStatic=True,
isCollectible=False,
isHazard=False
)
self.sounds = sounds
self.is_broken = False
self.dropped_item = None
def hit(self, player_pos):
"""Handle being hit by the player's weapon"""
if not self.is_broken:
self.is_broken = True
self.sounds['coffin_shatter'].play()
# Randomly choose item type
item_type = random.choice(['hand_of_glory', 'jack_o_lantern'])
# 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
)
return True
return False