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,
|
self.yPos,
|
||||||
item_type,
|
item_type,
|
||||||
self.sounds,
|
self.sounds,
|
||||||
direction
|
direction,
|
||||||
|
self.level.leftBoundary,
|
||||||
|
self.level.rightBoundary
|
||||||
)
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@@ -175,7 +175,9 @@ class Enemy(Object):
|
|||||||
self.yPos,
|
self.yPos,
|
||||||
itemType,
|
itemType,
|
||||||
self.sounds,
|
self.sounds,
|
||||||
direction
|
direction,
|
||||||
|
self.level.leftBoundary,
|
||||||
|
self.level.rightBoundary
|
||||||
)
|
)
|
||||||
self.level.bouncing_items.append(droppedItem)
|
self.level.bouncing_items.append(droppedItem)
|
||||||
|
|
||||||
|
@@ -265,7 +265,7 @@ class Level:
|
|||||||
obj.xPos >= attackRange[0] and
|
obj.xPos >= attackRange[0] and
|
||||||
obj.xPos <= attackRange[1] and
|
obj.xPos <= attackRange[1] and
|
||||||
self.player.isJumping): # Must be jumping to hit floating coffins
|
self.player.isJumping): # Must be jumping to hit floating coffins
|
||||||
|
|
||||||
if obj.hit(self.player.xPos):
|
if obj.hit(self.player.xPos):
|
||||||
self.bouncing_items.append(obj.dropped_item)
|
self.bouncing_items.append(obj.dropped_item)
|
||||||
|
|
||||||
@@ -368,7 +368,8 @@ class Level:
|
|||||||
play_sound(self.sounds[f'get_{obj.graveItem}'])
|
play_sound(self.sounds[f'get_{obj.graveItem}'])
|
||||||
self.player.stats.update_stat('Items collected', 1)
|
self.player.stats.update_stat('Items collected', 1)
|
||||||
# Create PowerUp to handle the item effect
|
# 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)
|
item.apply_effect(self.player)
|
||||||
# Stop grave's current audio channel
|
# Stop grave's current audio channel
|
||||||
if obj.channel:
|
if obj.channel:
|
||||||
|
@@ -3,7 +3,7 @@ from src.object import Object
|
|||||||
from src.weapon import Weapon
|
from src.weapon import Weapon
|
||||||
|
|
||||||
class PowerUp(Object):
|
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__(
|
super().__init__(
|
||||||
x, y, item_type,
|
x, y, item_type,
|
||||||
isStatic=False,
|
isStatic=False,
|
||||||
@@ -12,38 +12,45 @@ class PowerUp(Object):
|
|||||||
)
|
)
|
||||||
self.sounds = sounds
|
self.sounds = sounds
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
self.speed = 0.055 # Base movement speed
|
self.speed = 0.0525 # Base movement speed
|
||||||
self.item_type = item_type
|
self.item_type = item_type
|
||||||
self.channel = None
|
self.channel = None
|
||||||
self._currentX = x # Initialize the current x position
|
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):
|
def update(self, current_time, player_pos):
|
||||||
"""Update item position
|
"""Update item position"""
|
||||||
|
|
||||||
Args:
|
|
||||||
current_time: Current game time in milliseconds
|
|
||||||
player_pos: Current player x position
|
|
||||||
"""
|
|
||||||
if not self.isActive:
|
if not self.isActive:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Update position
|
# 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
|
# Update positional audio
|
||||||
if self.channel is None or not self.channel.get_busy():
|
if self.channel is None or not self.channel.get_busy():
|
||||||
self.channel = obj_play(self.sounds, "item_bounce", player_pos, self._currentX)
|
self.channel = obj_play(self.sounds, "item_bounce", player_pos, self._currentX)
|
||||||
else:
|
else:
|
||||||
self.channel = obj_update(self.channel, player_pos, self._currentX)
|
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:
|
if abs(self._currentX - player_pos) > 12:
|
||||||
self.isActive = False
|
self.isActive = False
|
||||||
if self.channel:
|
if self.channel:
|
||||||
self.channel.stop()
|
self.channel.stop()
|
||||||
self.channel = None
|
self.channel = None
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def apply_effect(self, player):
|
def apply_effect(self, player):
|
||||||
|
Reference in New Issue
Block a user