game: add: pladdle can move online with ping

This commit is contained in:
2024-01-18 14:40:31 +01:00
parent 251e9b032a
commit b0861b0ec0
2 changed files with 21 additions and 11 deletions

View File

@ -11,13 +11,16 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ...transcendence.abstract.AbstractRoomMember import AbstractRoomMember
from .Game import Game
class Player(Spectator):
def __init__(self, user_id: int, socket: WebsocketConsumer, rail_start_x: float, rail_start_y: float, rail_stop_x: float, rail_stop_y: float) -> None:
def __init__(self, game: Game, user_id: int, socket: WebsocketConsumer, rail_start_x: float, rail_start_y: float, rail_stop_x: float, rail_stop_y: float) -> None:
super().__init__(user_id, socket)
self.game: Game = game
self.position: Position = Position(0.5, 0)
self.nb_goal: int = 0
@ -93,7 +96,9 @@ class Player(Spectator):
self.position = new_position
if (invalid_pos):
self.game_member.send("update_paddle", self.to_dict())
self.send("update_paddle", self.to_dict())
self.game.broadcast("update_paddle", self.to_dict(), [self])
def to_dict(self):