From adb25e6ef6ab079e64b6900b462705d945aa99f2 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sat, 18 Oct 2025 01:43:40 +0200 Subject: [PATCH] feat: draw track borders --- src/game.py | 17 ++++++++++++++--- src/track.py | 4 ++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/game.py b/src/game.py index 2d01cd9..fbbb1db 100644 --- a/src/game.py +++ b/src/game.py @@ -49,8 +49,19 @@ class Game: def render(self): self.win.fill(self.BACKGROUND_COLOR) road: Road = self.track.objects[0] # type: ignore + + side1: list[Vec] = [] + side2: list[Vec] = [] + for i, pt in enumerate(road.pts): - pos: Vec = self.camera.world2screen(pt.pos) - col: float = i * 10 + 150 - pygame.draw.circle(self.win, (col, 100, 100), pos, 5) + p1: Vec = pt.pos + p2: Vec = p1 + pt.normal * pt.width + p3: Vec = p1 - pt.normal * pt.width + side1.append(self.camera.world2screen(p2)) + side2.append(self.camera.world2screen(p3)) + col: tuple[float, float, float] = (i * 10 + 150, 100, 100) + pygame.draw.circle(self.win, col, self.camera.world2screen(p1), 5) + + pygame.draw.lines(self.win, (255, 255, 255), True, side1) + pygame.draw.lines(self.win, (255, 255, 255), True, side2) pygame.display.flip() diff --git a/src/track.py b/src/track.py index 675d49c..c6b179f 100644 --- a/src/track.py +++ b/src/track.py @@ -41,9 +41,9 @@ class Track: class RoadPoint: - def __init__(self, pos: Vec, direction: Vec, width: float) -> None: + def __init__(self, pos: Vec, normal: Vec, width: float) -> None: self.pos: Vec = pos - self.direction: Vec = direction + self.normal: Vec = normal.normalized self.width: float = width @staticmethod