Items can no longer bounc past the end of level. Slight modification to item bounce speed, may need more adjustments.

This commit is contained in:
Storm Dragon
2025-02-11 22:50:26 -05:00
parent 8530993fa9
commit c6adc193a1
4 changed files with 31 additions and 18 deletions

View File

@@ -3,7 +3,7 @@ from src.object import Object
from src.weapon import Weapon
class PowerUp(Object):
def __init__(self, x, y, item_type, sounds, direction):
def __init__(self, x, y, item_type, sounds, direction, left_boundary=1, right_boundary=100):
super().__init__(
x, y, item_type,
isStatic=False,
@@ -12,38 +12,45 @@ class PowerUp(Object):
)
self.sounds = sounds
self.direction = direction
self.speed = 0.055 # Base movement speed
self.speed = 0.0525 # Base movement speed
self.item_type = item_type
self.channel = None
self._currentX = x # Initialize the current x position
self.left_boundary = left_boundary
self.right_boundary = right_boundary
def update(self, current_time, player_pos):
"""Update item position
Args:
current_time: Current game time in milliseconds
player_pos: Current player x position
"""
"""Update item position"""
if not self.isActive:
return False
# Update position
self._currentX += self.direction * self.speed
new_x = self._currentX + self.direction * self.speed
# Check boundaries and bounce if needed
if new_x < self.left_boundary:
self._currentX = self.left_boundary
self.direction = 1 # Start moving right
elif new_x > self.right_boundary:
self._currentX = self.right_boundary
self.direction = -1 # Start moving left
else:
self._currentX = new_x
# Update positional audio
if self.channel is None or not self.channel.get_busy():
self.channel = obj_play(self.sounds, "item_bounce", player_pos, self._currentX)
else:
self.channel = obj_update(self.channel, player_pos, self._currentX)
# Check if item has gone too far (12 tiles)
# Check if item is too far from player (12 tiles)
if abs(self._currentX - player_pos) > 12:
self.isActive = False
if self.channel:
self.channel.stop()
self.channel = None
return False
return True
def apply_effect(self, player):