68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
from libstormgames import *
|
|
from src.object import Object
|
|
from src.weapon import Weapon
|
|
|
|
class PowerUp(Object):
|
|
def __init__(self, x, y, item_type, sounds, direction):
|
|
super().__init__(
|
|
x, y, item_type,
|
|
isStatic=False,
|
|
isCollectible=True,
|
|
isHazard=False
|
|
)
|
|
self.sounds = sounds
|
|
self.direction = direction
|
|
self.speed = 0.05 # Base movement speed
|
|
self.item_type = item_type
|
|
self.channel = None
|
|
self._currentX = x # Initialize the current x position
|
|
|
|
def update(self, current_time):
|
|
"""Update item position"""
|
|
if not self.isActive:
|
|
return False
|
|
|
|
# Update position
|
|
self._currentX += self.direction * self.speed
|
|
|
|
# Update positional audio
|
|
if self.channel is None or not self.channel.get_busy():
|
|
self.channel = obj_play(self.sounds, "item_bounce", self.xPos, self._currentX)
|
|
else:
|
|
self.channel = obj_update(self.channel, self.xPos, self._currentX)
|
|
|
|
# Check if item has gone too far (20 tiles)
|
|
if abs(self._currentX - self.xRange[0]) > 20:
|
|
self.isActive = False
|
|
if self.channel:
|
|
self.channel.stop()
|
|
self.channel = None
|
|
return False
|
|
|
|
return True
|
|
|
|
def apply_effect(self, player):
|
|
"""Apply the item's effect when collected"""
|
|
if self.item_type == 'hand_of_glory':
|
|
player.start_invincibility()
|
|
elif self.item_type == 'cauldron':
|
|
player.restore_health()
|
|
elif self.item_type == 'guts':
|
|
player.add_guts()
|
|
elif self.item_type == 'jack_o_lantern':
|
|
player.add_jack_o_lantern()
|
|
elif self.item_type == 'extra_life':
|
|
player.extra_life()
|
|
elif self.item_type == 'witch_broom':
|
|
broomWeapon = Weapon.create_witch_broom()
|
|
player.add_weapon(broomWeapon)
|
|
player.equip_weapon(broomWeapon)
|
|
|
|
# Stop movement sound when collected
|
|
if self.channel:
|
|
self.channel.stop()
|
|
self.channel = None
|
|
|
|
# Item tracking
|
|
player.stats.update_stat('Items collected', 1)
|