game: advent to online

This commit is contained in:
2024-01-11 17:30:59 +01:00
parent ddc0698605
commit 134f1a8bd1
11 changed files with 151 additions and 21 deletions

View File

@ -1,4 +1,4 @@
PADDLE_SPEED_MAX = 1
PADDLE_SPEED_PER_SECOND_MAX = 0.5
PADDLE_RATIO = 0.1
MAP_SIZE_X = 900
@ -9,3 +9,5 @@ WALL_RATIO = 1
BALL_SPEED_INC = 1
BALL_SPEED_START = 1
BALL_SIZE = 4
BALL_SPAWN_POS_X = MAP_SIZE_X / 2
BALL_SPAWN_POS_Y = MAP_SIZE_Y / 2

View File

@ -28,7 +28,7 @@ class GameWebSocket(AsyncWebsocketConsumer):
self.room = game_room_manager.get(self.game_id)
if (self.room is None):
self.member.send("Game not found.")
self.send("Game not found.")
self.disconnect(1017)
self.room.append(self.member)

8
games/objects/Ball.py Normal file
View File

@ -0,0 +1,8 @@
from .. import config
class Ball:
def __init__(self) -> None:
self.x: float = config.BALL_SPAWN_POS_X
self.y: float = config.BALL_SPAWN_POS_Y

8
games/objects/Game.py Normal file
View File

@ -0,0 +1,8 @@
from .Ball import Ball
from .Paddle import Paddle
class Game:
def __init__(self, paddles: [Paddle], ball: Ball) -> None:
self.ball: Ball = ball
self.paddles: [paddles] = paddles

View File

@ -14,4 +14,5 @@ class GameMember(AbstractRoomMember):
return
def send_ball(self, ball):
pass
self.send("update_ball_pos", {"x": ball.x,
"y": ball.y})

8
games/objects/Paddle.py Normal file
View File

@ -0,0 +1,8 @@
class Player:
def __init__(self, user_id, pos, nb_goal) -> None:
self.user_id = user_id
self.pos = pos
self.nb_goal = nb_goal