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:
@@ -55,7 +55,10 @@ class CoffinObject(Object):
|
||||
self.yPos,
|
||||
item_type,
|
||||
self.sounds,
|
||||
direction
|
||||
direction,
|
||||
self.level.leftBoundary,
|
||||
self.level.rightBoundary
|
||||
)
|
||||
|
||||
return True
|
||||
return False
|
||||
|
@@ -175,7 +175,9 @@ class Enemy(Object):
|
||||
self.yPos,
|
||||
itemType,
|
||||
self.sounds,
|
||||
direction
|
||||
direction,
|
||||
self.level.leftBoundary,
|
||||
self.level.rightBoundary
|
||||
)
|
||||
self.level.bouncing_items.append(droppedItem)
|
||||
|
||||
|
@@ -368,7 +368,8 @@ class Level:
|
||||
play_sound(self.sounds[f'get_{obj.graveItem}'])
|
||||
self.player.stats.update_stat('Items collected', 1)
|
||||
# Create PowerUp to handle the item effect
|
||||
item = PowerUp(obj.xPos, obj.yPos, obj.graveItem, self.sounds, 1)
|
||||
item = PowerUp(obj.xPos, obj.yPos, obj.graveItem, self.sounds, 1,
|
||||
self.leftBoundary, self.rightBoundary)
|
||||
item.apply_effect(self.player)
|
||||
# Stop grave's current audio channel
|
||||
if obj.channel:
|
||||
|
@@ -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,23 +12,30 @@ 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():
|
||||
@@ -36,7 +43,7 @@ class PowerUp(Object):
|
||||
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:
|
||||
|
Reference in New Issue
Block a user