Désactivation des collisions internes des objets (#12)

Cela devrais régler les problèmes de lag spikes et permet de mettre les murs au bords de l'écrans sans rebonds étranges.

Reviewed-on: #12
Reviewed-by: Corentin <solois.corentin@gmail.com>
Co-authored-by: Tipragot <contact@tipragot.fr>
Co-committed-by: Tipragot <contact@tipragot.fr>
This commit is contained in:
Tipragot 2024-01-07 09:22:03 +00:00 committed by Corentin
parent 824015228a
commit af69b53967
2 changed files with 12 additions and 2 deletions

View file

@ -60,6 +60,14 @@ class AABB:
self.min += movement self.min += movement
self.max += movement self.max += movement
def collide(self, other: "AABB"):
return (
self.min.x < other.max.x
and self.max.x > other.min.x
and self.min.y < other.max.y
and self.max.y > other.min.y
)
def line_to_line(sa: Vec2, ea: Vec2, sb: Vec2, eb: Vec2): def line_to_line(sa: Vec2, ea: Vec2, sb: Vec2, eb: Vec2):
""" """
@ -117,6 +125,8 @@ def aabb_to_aabb(moving: AABB, static: AABB, movement: Vec2):
""" """
Renvoie la collision entre deux AABB. Renvoie la collision entre deux AABB.
""" """
if moving.collide(static):
return 1.0, Vec2(0, 0)
size = (moving.max - moving.min) / 2 size = (moving.max - moving.min) / 2
static = AABB(static.min - size, static.max + size, static.entity) static = AABB(static.min - size, static.max + size, static.entity)
start_pos = moving.min + size start_pos = moving.min + size

View file

@ -219,7 +219,7 @@ def __spawn_ellements(world: World):
world.new_entity().set( world.new_entity().set(
Origin(Vec2(1, 0)), Origin(Vec2(1, 0)),
Scale(Vec2(10, render.HEIGHT)), Scale(Vec2(10, render.HEIGHT)),
Position(Vec2(70, 0)), Position(Vec2(0, 0)),
Solid(), Solid(),
LeftWall(), LeftWall(),
CollisionHandler(__bounce_on_left_wall), CollisionHandler(__bounce_on_left_wall),
@ -229,7 +229,7 @@ def __spawn_ellements(world: World):
world.new_entity().set( world.new_entity().set(
Origin(Vec2(0, 0)), Origin(Vec2(0, 0)),
Scale(Vec2(10, render.HEIGHT)), Scale(Vec2(10, render.HEIGHT)),
Position(Vec2(render.WIDTH - 70, 0)), Position(Vec2(render.WIDTH, 0)),
Solid(), Solid(),
RightWall(), RightWall(),
CollisionHandler(__bounce_on_right_wall), CollisionHandler(__bounce_on_right_wall),