summaryrefslogtreecommitdiff
path: root/server/server.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-02-03 01:32:09 +0000
committerubq323 <ubq323@ubq323.website>2023-02-03 01:32:09 +0000
commitec6a391cb9cf0c0feac0fe3615a59cc7cb6db2d5 (patch)
tree1893ad4fe5dc651370411f2bc84060cd7c0465cb /server/server.lua
parent04664ee48de5fc8b06a584e20a4b75c41dafa558 (diff)
drawing changes, world generation, perlin noise
Diffstat (limited to 'server/server.lua')
-rw-r--r--server/server.lua17
1 files changed, 15 insertions, 2 deletions
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