game: add: main loop

This commit is contained in:
starnakin 2024-01-19 15:35:46 +01:00
parent 13c49ed3c3
commit 2f4496c9bc

View File

@ -0,0 +1,29 @@
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from .objects.Spectator import Spectator
from .objects.Player import Player
from .objects.Game import Game
from . import config
from time import sleep
def routine(game: Game):
while True:
for player in game._updated_players:
game.broadcast("update_paddle", player.to_dict(), [player])
game._updated_players.clear()
if (game.started):
game.ball.postion_x = game.ball.postion_x + game.ball.velocity_x
game.ball.postion_y = game.ball.postion_y + game.ball.velocity_y
game.broadcast("update_ball", game.ball.to_dict())
sleep(1 / config.SERVER_TPS)