ping fix
This commit is contained in:
parent
75eaf59c79
commit
6392bf00d6
3 changed files with 37 additions and 10 deletions
18
server.py
18
server.py
|
@ -1,5 +1,5 @@
|
|||
from websockets.server import serve, ServerConnection
|
||||
import random, sys, asyncio
|
||||
import random, sys, asyncio, time
|
||||
|
||||
class Block:
|
||||
def __init__(self, x, y, block_type, color, collides):
|
||||
|
@ -169,8 +169,12 @@ class Player(Block):
|
|||
# pass
|
||||
|
||||
async def render(self):
|
||||
await self.setVel(self.vel_x * 0.5, self.vel_y * 0.5)
|
||||
await self.setPos(self.x + self.vel_x, self.y + self.vel_y)
|
||||
self.vel_x *= 0.5
|
||||
self.vel_y *= 0.5
|
||||
self.x += self.vel_x
|
||||
self.y += self.vel_y
|
||||
# await self.setVel(self.vel_x * 0.5, self.vel_y * 0.5)
|
||||
# await self.setPos(self.x + self.vel_x, self.y + self.vel_y)
|
||||
return self.vel_x != 0 or self.vel_y != 0
|
||||
|
||||
def toStatement(self, add=True):
|
||||
|
@ -189,6 +193,9 @@ def getPlayer(name):
|
|||
if b.name == name:
|
||||
return b
|
||||
|
||||
def current_milli_time():
|
||||
return round(time.time() * 1000)
|
||||
|
||||
async def readPacket(websocket: ServerConnection) -> tuple[str, list[str]]:
|
||||
data = await websocket.recv()
|
||||
return data[0], data[1:].splitlines()
|
||||
|
@ -264,6 +271,11 @@ async def handler(websocket: ServerConnection):
|
|||
|
||||
print(message)
|
||||
|
||||
if packet_id == "R":
|
||||
rid, x, y = packet_data
|
||||
|
||||
writePacket(websocket, "R", [rid, str(current_milli_time()), str(player.vel_x + (x - player.x)), str(player.vel_y + (y - player.y))])
|
||||
|
||||
if packet_id == "D":
|
||||
x,y = packet_data
|
||||
x,y = int(x),int(y)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue