diff --git a/src/plugins/physics.py b/src/plugins/physics.py index 8879d4f..86d15c9 100644 --- a/src/plugins/physics.py +++ b/src/plugins/physics.py @@ -60,6 +60,14 @@ class AABB: self.min += 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): """ @@ -117,6 +125,8 @@ def aabb_to_aabb(moving: AABB, static: AABB, movement: Vec2): """ Renvoie la collision entre deux AABB. """ + if moving.collide(static): + return 1.0, Vec2(0, 0) size = (moving.max - moving.min) / 2 static = AABB(static.min - size, static.max + size, static.entity) start_pos = moving.min + size diff --git a/src/scenes/game.py b/src/scenes/game.py index ae225ed..8eefe9a 100644 --- a/src/scenes/game.py +++ b/src/scenes/game.py @@ -219,7 +219,7 @@ def __spawn_ellements(world: World): world.new_entity().set( Origin(Vec2(1, 0)), Scale(Vec2(10, render.HEIGHT)), - Position(Vec2(70, 0)), + Position(Vec2(0, 0)), Solid(), LeftWall(), CollisionHandler(__bounce_on_left_wall), @@ -229,7 +229,7 @@ def __spawn_ellements(world: World): world.new_entity().set( Origin(Vec2(0, 0)), Scale(Vec2(10, render.HEIGHT)), - Position(Vec2(render.WIDTH - 70, 0)), + Position(Vec2(render.WIDTH, 0)), Solid(), RightWall(), CollisionHandler(__bounce_on_right_wall),