Code cleanup, added more functionality. Floating coffins that spawn items, graves can spawn zombies, etc.
This commit is contained in:
40
src/coffin.py
Normal file
40
src/coffin.py
Normal 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
|
Reference in New Issue
Block a user