diff --git a/README.md b/README.md index f274e42..40306ed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # cubicjs -сайт: https://meex.lol/cubic/client/index.html +сайт: https://meex.lol/cubic/ ## роадмап diff --git a/build.sh b/client/build.sh old mode 100644 new mode 100755 similarity index 100% rename from build.sh rename to client/build.sh diff --git a/index.html b/client/index.html similarity index 100% rename from index.html rename to client/index.html diff --git a/src/block.ts b/client/src/block.ts similarity index 100% rename from src/block.ts rename to client/src/block.ts diff --git a/src/core.ts b/client/src/core.ts similarity index 100% rename from src/core.ts rename to client/src/core.ts diff --git a/src/main.ts b/client/src/main.ts similarity index 100% rename from src/main.ts rename to client/src/main.ts diff --git a/src/network.ts b/client/src/network.ts similarity index 100% rename from src/network.ts rename to client/src/network.ts diff --git a/src/player.ts b/client/src/player.ts similarity index 100% rename from src/player.ts rename to client/src/player.ts diff --git a/tsconfig.json b/client/tsconfig.json similarity index 100% rename from tsconfig.json rename to client/tsconfig.json diff --git a/server/src/__main__.py b/server/src/__main__.py index df62e90..1b3f4a1 100644 --- a/server/src/__main__.py +++ b/server/src/__main__.py @@ -1,16 +1,27 @@ -import asyncio +import asyncio, time from network import startServer +from player import Player +from block import Block from world import * from config import * +def current_milli_time(): + return round(time.time() * 1000) + async def tickTimer(): while True: for b in WORLD: await b.tick() await asyncio.sleep(1/20) +async def keepAliveTimer(): + while True: + for b in getPlayers(): + await b.keepAlive() + await asyncio.sleep(1) + async def renderTimer(): while True: for p in getPlayers(): @@ -19,6 +30,7 @@ async def renderTimer(): async def main(): asyncio.get_event_loop().create_task(tickTimer()) + asyncio.get_event_loop().create_task(keepAliveTimer()) asyncio.get_event_loop().create_task(renderTimer()) await startServer(HOST, PORT) diff --git a/server/src/player.py b/server/src/player.py index 24f06a0..6a09ac0 100644 --- a/server/src/player.py +++ b/server/src/player.py @@ -231,13 +231,25 @@ class Player(Block): async def onCollide(self, player, x, y): await super().onCollide(player, x, y) + # if x != 0: + # player.vel_x *= 0.5 + # self.vel_x = player.vel_x + # if y != 0: + # player.vel_y *= 0.5 + # self.vel_y = player.vel_y + # pass async def render(self): 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 + async def keepAlive(self): + await self.sendPacket("R", [str(self.x), str(self.y), str(self.vel_x), str(self.vel_y)]) + def toStatement(self, add=True): return f"P1{self.name},{self.x},{self.y},{self.vel_x},{self.vel_y},{self.color}" if add else f"P0{self.name}"