feat: add connected indicator on car

This commit is contained in:
2025-10-22 23:57:41 +02:00
parent f91a4e8d61
commit 8542ee81e7
3 changed files with 16 additions and 0 deletions

View File

@@ -45,3 +45,6 @@ class Camera:
screen_delta: Vec = Vec(dx, dy) * self.zoom * self.UNIT_RATIO
screen_pos: Vec = self.car_screen_pos + screen_delta
return screen_pos
def size2screen(self, size: float) -> float:
return size * self.zoom * self.UNIT_RATIO

View File

@@ -16,6 +16,7 @@ class Car:
MAX_BACK_SPEED = -3
ROTATE_SPEED = 1
COLOR = (230, 150, 80)
CTRL_COLOR = (80, 230, 150)
WIDTH = 0.4
LENGTH = 0.6
COLLISION_MARGIN = 0.4
@@ -82,6 +83,14 @@ class Car:
pts = [camera.world2screen(p) for p in pts]
pygame.draw.polygon(surf, self.COLOR, pts)
if self.controller.is_connected:
pygame.draw.circle(
surf,
self.CTRL_COLOR,
camera.world2screen(self.pos),
camera.size2screen(self.WIDTH / 4),
)
def get_corners(self) -> list[Vec]:
u: Vec = self.direction * self.LENGTH / 2
v: Vec = self.direction.perp * self.WIDTH / 2

View File

@@ -35,6 +35,10 @@ class RemoteController:
self.client_thread: Optional[threading.Thread] = None
self.client: Optional[socket.socket] = None
@property
def is_connected(self) -> bool:
return self.client is not None
def wait_for_connections(self):
self.server.bind(("", self.port))
self.server.listen(1)