feat: draw track borders
This commit is contained in:
17
src/game.py
17
src/game.py
@@ -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()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user