Save unfinished work

This commit is contained in:
Tipragot 2024-01-07 08:56:00 +01:00
parent ea70c297b2
commit 4cc7806a23
2 changed files with 12 additions and 2 deletions

View file

@ -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

View file

@ -213,7 +213,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),
@ -223,7 +223,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),