From ec6a391cb9cf0c0feac0fe3615a59cc7cb6db2d5 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 3 Feb 2023 01:32:09 +0000 Subject: drawing changes, world generation, perlin noise --- server/server.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'server/server.lua') diff --git a/server/server.lua b/server/server.lua index ff3c3eb..67860ea 100644 --- a/server/server.lua +++ b/server/server.lua @@ -1,6 +1,8 @@ local enet = require"enet" local json = require"common.dkjson" +local chunk = require"common.chunk" local Chunk = require"common.chunk".Chunk +local noise = require"noise" local unpack = unpack or table.unpack local coords = require"common.coords" @@ -58,7 +60,18 @@ local function player_move_packet(player,x,y) return json.encode{t="move",id=player.id,x=x,y=y} end -local the_chunk = Chunk.gen() +local the_tiles = {} +local ng = noise.NoiseAgg.make_perlin_octaves(4) +for q = 1,chunk.SIZE-1 do + for r = 1,chunk.SIZE-1 do + local p = coords.Hex.make(q,r):to_pos() + local nv = ng:at(p.x/20,p.y/20) + assert(nv ~= 1,"oopsy") + the_tiles[chunk.index(q,r)] = nv > 0 and 1+math.floor(math.sqrt(nv)*8) or false + end +end +local the_chunk = Chunk.make(the_tiles) +print"generated chunk" while true do local ev = host:service(100) @@ -104,7 +117,7 @@ while true do elseif op == "settile" then local h = coords.Hex.make(j.q,j.r) the_chunk:set_at(h,j.tile) - print(player.id,"settile",h,j.tile) + -- print(player.id,"settile",h,j.tile) for i,otherplayer in ipairs(playerlist) do if otherplayer ~= player then -- same packet structure s2c as c2s -- cgit v1.2.3