Désactivation des collisions internes des objets #12
|
@ -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
|
||||||
|
|
|
@ -213,7 +213,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),
|
||||||
|
@ -223,7 +223,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),
|
||||||
|
|
Loading…
Reference in a new issue