Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fill_region(map, x, y, n, v)
- local i, j
- for i = x, x + n do
- for j = y, y + n do
- map[i][j] = v
- end
- end
- return map
- end
- function check_map(map, size)
- local x, y, t
- t = 0
- for x = 0, size do
- for y = 0, size do
- if map[x][y] == 1 then
- t = t + 1
- end
- end
- end
- return t
- end
- function create_map(map, size)
- map = {}
- for x = 0, size do
- map[x] = {}
- for y = 0, size do
- map[x][y] = 1
- end
- end
- return map
- end
- function start_map(map, size)
- map = create_map(map, size)
- --[[
- local x, y
- for x = 0, size, size/4 do
- for y = 0, size, size/4 do
- if x < size and y < size then
- map = fill_region(map, x, y, size/4, stead.rnd(2) - 1)
- end
- end
- end
- ]]--
- local i
- local n = 8
- for i = 0, size, size/n do
- if i < size then
- map = fill_region(map, i, 0, size/n, 0)
- map = fill_region(map, i, size - size/n - 1, size/n, 0)
- map = fill_region(map, 0, i, size/n, 0)
- map = fill_region(map, size - size/n - 1, i, size/n, 0)
- end
- end
- map = fill_region(map, size/n*3, size/n*3, size/n, 0)
- return map
- end
- function build_map(map, size)
- local x, y, n, t
- local i = 32
- map = start_map(map, size)
- n = size/i
- while n > 0 do
- for x = 0, size, n do
- for y = 0, size, n do
- local dx, dy = 0, 0
- t = stead.rnd(2)
- if t == 1 then
- dx = math.floor((x + n) / (n * 2) * n * 2)
- else
- dx = math.floor((x - n) / (n * 2) * n * 2)
- end
- t = stead.rnd(2)
- if t == 1 then
- dy = math.floor((y + n) / (n * 2) * n * 2)
- else
- dy = math.floor((y - n) / (n * 2) * n * 2)
- end
- if dx >= size then dx = 0 end
- if dx < 0 then dx = size - n end
- if dy >= size then dy = 0 end
- if dy < 0 then dy = size - n end
- if x < size and y < size then
- map = fill_region(map, x, y, n, map[dx][dy])
- end
- end
- end
- n = math.floor(n / 2)
- end
- return map
- end
- function world_goodiser(map, size, i)
- local nmap = {}
- local n
- nmap = create_map(nmap, size)
- for n = 1, i do
- for x = 0, size do
- for y = 0, size do
- local c = 0
- local dx, dy
- for dx = x - 3, x + 3 do
- for dy = y - 3, y + 3 do
- if dx >= 0 and dy >= 0 and dx <= size and dy <= size then
- c = c + map[dx][dy]
- if c > 30 then
- nmap[x][y] = 1
- else
- nmap[x][y] = 0
- end
- end
- end
- end
- end
- end
- end
- return nmap
- end
- function generate_world(map, size)
- local t
- t = 0
- while t < size*size/2.1 or t > size*size/1.9 do
- print(t)
- map = build_map(map, size)
- t = check_map(map, size)
- end
- map = world_goodiser(map, size, 3)
- return map
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement