From 9acea09359827d4b61e9894f761ba3c90cdfd5f3 Mon Sep 17 00:00:00 2001 From: Skyball2000 Date: Wed, 29 Mar 2023 16:17:34 +0200 Subject: [PATCH] Fixed box glitch --- project/physics/PhysicsElementsHandler.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/project/physics/PhysicsElementsHandler.py b/project/physics/PhysicsElementsHandler.py index 2f38802..ecb5274 100644 --- a/project/physics/PhysicsElementsHandler.py +++ b/project/physics/PhysicsElementsHandler.py @@ -58,10 +58,19 @@ class PhysicsElementsHandler: skip_sprites = [] for sprite in sorted_dynamic_sprites: - if sprite.last_effective_motion == (0, 0) and random.randint(0, 100) > 50\ + if sprite.last_effective_motion == (0, 0) and random.randint(0, 100) > 50 \ and not sprite.id == 'player': skip_sprites.append(sprite) continue + + # remove all skip sprites that are closer than 100 pixels to the player + players = [sprite for sprite in sprites if hasattr(sprite, 'id') and sprite.id == 'player'] + if len(players) > 0: + player = players[0] + for sprite in skip_sprites: + if sprite.position_scale.position[1] - player.position_scale.position[1] < 100: + skip_sprites.remove(sprite) + sorted_dynamic_sprites = [sprite for sprite in sorted_dynamic_sprites if sprite not in skip_sprites] closest_sprites: dict[UiElement, list[tuple[int, StaticSprite]]] = {}