Performance improvements
parent
7cac2c2a7a
commit
7a5987b3d2
|
@ -53,6 +53,7 @@ class LoadedLevel:
|
||||||
if isinstance(element, SimpleBlockLevelElement):
|
if isinstance(element, SimpleBlockLevelElement):
|
||||||
if self.is_surrounded_by_blocks(world_position, level.tiles):
|
if self.is_surrounded_by_blocks(world_position, level.tiles):
|
||||||
element.is_collider = False
|
element.is_collider = False
|
||||||
|
element.register_collisions = False
|
||||||
# self.sprite_manager.remove_ui_element(element)
|
# self.sprite_manager.remove_ui_element(element)
|
||||||
|
|
||||||
def is_surrounded_by_blocks(self, position, tiles):
|
def is_surrounded_by_blocks(self, position, tiles):
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import math
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from physics.CollisionDirection import CollisionDirection
|
from physics.CollisionDirection import CollisionDirection
|
||||||
|
@ -161,9 +162,16 @@ class PhysicsElementsHandler:
|
||||||
|
|
||||||
for collider in colliders:
|
for collider in colliders:
|
||||||
if sprite is not collider:
|
if sprite is not collider:
|
||||||
|
distance = self.calculate_basic_distance(sprite, collider)
|
||||||
|
if distance > 50:
|
||||||
|
continue
|
||||||
if sprite.collides_with(collider, TOLERANCE):
|
if sprite.collides_with(collider, TOLERANCE):
|
||||||
collides_with.append(collider)
|
collides_with.append(collider)
|
||||||
if len(collides_with) >= 2:
|
if len(collides_with) >= 2:
|
||||||
break
|
break
|
||||||
|
|
||||||
return collides_with
|
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)
|
||||||
|
|
Loading…
Reference in New Issue