Performance improvements

main
Yan Wittmann 2023-03-27 15:17:01 +02:00
parent 7cac2c2a7a
commit 7a5987b3d2
2 changed files with 10 additions and 1 deletions

View File

@ -53,7 +53,8 @@ class LoadedLevel:
if isinstance(element, SimpleBlockLevelElement):
if self.is_surrounded_by_blocks(world_position, level.tiles):
element.is_collider = False
#self.sprite_manager.remove_ui_element(element)
element.register_collisions = False
# self.sprite_manager.remove_ui_element(element)
def is_surrounded_by_blocks(self, position, tiles):
for i in range(-1, 2):

View File

@ -1,3 +1,4 @@
import math
from typing import Optional
from physics.CollisionDirection import CollisionDirection
@ -161,9 +162,16 @@ class PhysicsElementsHandler:
for collider in colliders:
if sprite is not collider:
distance = self.calculate_basic_distance(sprite, collider)
if distance > 50:
continue
if sprite.collides_with(collider, TOLERANCE):
collides_with.append(collider)
if len(collides_with) >= 2:
break
return collides_with
def calculate_basic_distance(self, sprite1: StaticSprite, sprite2: StaticSprite) -> float:
return math.sqrt((sprite1.position_scale.position[0] - sprite2.position_scale.position[0]) ** 2 +
(sprite1.position_scale.position[1] - sprite2.position_scale.position[1]) ** 2)