1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
local coords = require"common.coords"
local noise = require"noise"
local chunk = require"common.chunk"
local CHUNK_SIZE = require"common.constants".CHUNK_SIZE
local function p(amp,scale) return {scale=scale,amp=amp,gen=noise.PerlinNoise:make()} end
-- local ng = noise.NoiseAgg:make{
-- p(1,20),
-- -- p(0.7,2),
-- p(0.5,15),
-- --p(2,200),
-- }
-- whether there is a tile there or not
local surface_ng = noise.NoiseAgg:make{p(1,20),p(0.5,15)}
-- if there is a tile there, what color should it be
local color_ng = noise.NoiseAgg:make{p(1,20),p(0.5,15)}
local function gen_chunk(chpos)
local htl,hbr = chpos:extents()
local tiles = {}
for q = 0,CHUNK_SIZE-1 do
for r = 0,CHUNK_SIZE-1 do
local p = (htl+coords.Hex:make(q,r)):to_pos()
local ix = chunk.index(q,r)
local nv = surface_ng:at(p.x,p.y)
if nv <= 0 then
tiles[ix] = false
else
local nv2 = color_ng:at(p.x,p.y)
nv2 = math.max(-0.9999999,math.min(0.9999999,nv2*2.5))
nv2 = (nv2+1)/2
local tv = 1+math.floor(nv2*8)
assert(1<=tv and tv<=8,"oopsy woopsy")
tiles[ix] = tv
end
end
end
local the_chunk = chunk.Chunk:make(chpos,tiles)
return the_chunk
end
return {
gen_chunk=gen_chunk
}
|