diff options
author | ubq323 <ubq323@ubq323.website> | 2023-01-31 00:30:47 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-01-31 00:30:47 +0000 |
commit | 91a22ac34a3e6dc8536298537796e101424a430c (patch) | |
tree | 2bcdd770d695ff0a3fef8ba33590029754e4cc3f /client/main.lua | |
parent | b851e37a5a44e2c6a022f1c87c3d2da494ccb0e6 (diff) |
terrain data is sent from server to client
Diffstat (limited to 'client/main.lua')
-rw-r--r-- | client/main.lua | 10 |
1 files changed, 8 insertions, 2 deletions
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) |