feat: draw track borders

This commit is contained in:
2025-10-18 01:43:40 +02:00
parent 6276f97cce
commit adb25e6ef6
2 changed files with 16 additions and 5 deletions

View File

@@ -49,8 +49,19 @@ class Game:
def render(self): def render(self):
self.win.fill(self.BACKGROUND_COLOR) self.win.fill(self.BACKGROUND_COLOR)
road: Road = self.track.objects[0] # type: ignore road: Road = self.track.objects[0] # type: ignore
side1: list[Vec] = []
side2: list[Vec] = []
for i, pt in enumerate(road.pts): for i, pt in enumerate(road.pts):
pos: Vec = self.camera.world2screen(pt.pos) p1: Vec = pt.pos
col: float = i * 10 + 150 p2: Vec = p1 + pt.normal * pt.width
pygame.draw.circle(self.win, (col, 100, 100), pos, 5) 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() pygame.display.flip()

View File

@@ -41,9 +41,9 @@ class Track:
class RoadPoint: 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.pos: Vec = pos
self.direction: Vec = direction self.normal: Vec = normal.normalized
self.width: float = width self.width: float = width
@staticmethod @staticmethod