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,,,,,,,,,,,#
|
||||
#,,,,,,,,,,,+,+,+,+,+,+,+,+,+,+,+,+,+,+,+,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
|
||||
#,L,,,,,,,,,,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
|
||||
|
|
|
|
@ -1,3 +1,4 @@
|
|||
import random
|
||||
from typing import Optional
|
||||
|
||||
from physics.CollisionDirection import CollisionDirection
|
||||
|
@ -55,6 +56,14 @@ class PhysicsElementsHandler:
|
|||
dynamic_sprites = [sprite for sprite in sprites if isinstance(sprite, DynamicSprite)]
|
||||
sorted_dynamic_sprites = sorted(dynamic_sprites, key=lambda spr: spr.position_scale.position[1])
|
||||
|
||||
skip_sprites = []
|
||||
for sprite in sorted_dynamic_sprites:
|
||||
if sprite.last_effective_motion[1] == 0 and sprite.last_effective_motion[0] == 0 \
|
||||
and random.randint(0, 100) > 50:
|
||||
skip_sprites.append(sprite)
|
||||
continue
|
||||
sorted_dynamic_sprites = [sprite for sprite in sorted_dynamic_sprites if sprite not in skip_sprites]
|
||||
|
||||
closest_sprites: dict[UiElement, list[tuple[int, StaticSprite]]] = {}
|
||||
|
||||
buffered_bounding_boxes: dict[UiElement, BoundingBox] = {}
|
||||
|
@ -123,6 +132,7 @@ class PhysicsElementsHandler:
|
|||
|
||||
collides_with_last = None
|
||||
collided = [False, False]
|
||||
effective_motion = [0, 0]
|
||||
|
||||
for i in range(motion_steps):
|
||||
if not collided[0]:
|
||||
|
@ -132,6 +142,9 @@ class PhysicsElementsHandler:
|
|||
)
|
||||
|
||||
collides_with = self.check_collides(sprite, colliders)
|
||||
if len(collides_with) == 0:
|
||||
effective_motion[0] += motion_step[0]
|
||||
|
||||
for collider in collides_with:
|
||||
if collider is not None:
|
||||
if sprite.is_collider and collider.is_collider:
|
||||
|
@ -176,6 +189,9 @@ class PhysicsElementsHandler:
|
|||
)
|
||||
|
||||
collides_with = self.check_collides(sprite, colliders)
|
||||
if len(collides_with) == 0:
|
||||
effective_motion[1] += motion_step[1]
|
||||
|
||||
for collider in collides_with:
|
||||
if collider is not None:
|
||||
if sprite.is_collider and collider.is_collider:
|
||||
|
@ -213,6 +229,8 @@ class PhysicsElementsHandler:
|
|||
collides_with_last = collider
|
||||
collided[1] = True
|
||||
|
||||
sprite.last_effective_motion = (sprite.motion[0], sprite.motion[1])
|
||||
|
||||
return collides_with_last
|
||||
|
||||
def check_collides(self, sprite: StaticSprite, colliders: list[StaticSprite]) -> list[StaticSprite]:
|
||||
|
|
|
@ -11,6 +11,7 @@ class DynamicSprite(StaticSprite):
|
|||
super().__init__(spritesheet)
|
||||
|
||||
self.motion = (0, 0)
|
||||
self.last_effective_motion = (1, 1)
|
||||
|
||||
self.apply_base_deceleration = True
|
||||
self.deceleration_horizontal_air = 0.02
|
||||
|
|
Loading…
Reference in New Issue