From 91a22ac34a3e6dc8536298537796e101424a430c Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 31 Jan 2023 00:30:47 +0000 Subject: terrain data is sent from server to client --- client/main.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'client/main.lua') diff --git a/client/main.lua b/client/main.lua index b2e2b3f..819753f 100644 --- a/client/main.lua +++ b/client/main.lua @@ -11,6 +11,7 @@ local drawing = require"drawing" local coords = require"common.coords" local Pos = coords.Pos local camera = require"camera".Camera.make() +local Chunk = require"common.chunk".Chunk -- local pprint=require"common.pprint" -- pprint.setup{show_all=true} @@ -20,7 +21,7 @@ math.randomseed(os.time()) local host,peer -local chunk = require"common.chunk".Chunk.make() +local chunk local function draw_player(pl,islocal) local hplsz = PLAYER_SIZE/2 @@ -78,6 +79,7 @@ function love.update(dt) repeat local ev = host:service() if ev and ev.type == "receive" then + print(ev.data) local j = json.decode(ev.data) local op = j.t if op == "join" then @@ -94,6 +96,8 @@ function love.update(dt) elseif op == "you" then local pl = j.pl local_player = {pos=coords.Pos.make(pl.x,pl.y),color=pl.color,id=pl.id} + elseif op == "chunk" then + chunk = Chunk.from_packet_data(j) end end until not ev @@ -107,7 +111,9 @@ function love.draw() end camera:apply_trans() - drawing.draw_chunk(camera,chunk) + if chunk then + drawing.draw_chunk(camera,chunk) + end if local_player then draw_player(local_player,true) -- cgit v1.2.3