mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-30 04:30:58 +02:00
Added maze
This commit is contained in:
parent
f582cb862c
commit
c2c443e2ce
@ -1,11 +1,10 @@
|
||||
local wall_thickness = 1
|
||||
local cell_size = 1 --must be an uneven number
|
||||
local cell_size = 3 --must be an uneven number
|
||||
|
||||
|
||||
local wall_delta = math.floor((cell_size-wall_thickness)/2)
|
||||
local chunk_size = 32
|
||||
|
||||
rects = {}
|
||||
pixels = {}
|
||||
cells = {}
|
||||
function add_tile(x, y, width, height, add_cell)
|
||||
@ -21,22 +20,30 @@ function add_tile(x, y, width, height, add_cell)
|
||||
end
|
||||
end
|
||||
|
||||
local max = 0
|
||||
global.max = 0
|
||||
function render()
|
||||
for x,_ in pairs(pixels) do
|
||||
for y,_ in pairs(pixels[x]) do
|
||||
if y * 32 > max and y % 2 == 0 then
|
||||
max = y * 32
|
||||
if y * 32 > global.max and y % 2 == 0 then
|
||||
global.max = y * 32
|
||||
end
|
||||
rects[x*32 .. "/" .. y*32] = 1
|
||||
global.rects[x*32 .. "/" .. y*32] = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
global.rnd_p = 1
|
||||
function psd_rnd(l, h)
|
||||
while global.shuffle_pool[global.rnd_p] < l do
|
||||
global.rnd_p = global.rnd_p + 1
|
||||
end
|
||||
local res = global.shuffle_pool[global.rnd_p]
|
||||
global.rnd_p = global.rnd_p + 1
|
||||
return res
|
||||
end
|
||||
function shuffle(t)
|
||||
for i = 1, #t - 1 do
|
||||
local r = math.random(i, #t)
|
||||
local r = psd_rnd(i, #t)
|
||||
t[i], t[r] = t[r], t[i]
|
||||
end
|
||||
end
|
||||
@ -86,8 +93,7 @@ function make_maze(w, h)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
walk(math.random(1, w)*2, math.random(1, h)*2)
|
||||
walk(global.walk_seed_w, global.walk_seed_h)
|
||||
|
||||
local s = {}
|
||||
for i = 1, h*2+1 do
|
||||
@ -119,22 +125,41 @@ local function reduce_walls()
|
||||
end
|
||||
end
|
||||
function init()
|
||||
game.print(game.tick)
|
||||
-- math.randomseed( 78579837297 )
|
||||
make_maze(40, 40)
|
||||
if not global.walk_seed_w then global.walk_seed_w = math.random(1, 50)*2 end
|
||||
if not global.rects then global.rects = {} end
|
||||
if not global.walk_seed_h then global.walk_seed_h = math.random(1, 50)*2 end
|
||||
if not global.shuffle_pool then
|
||||
global.shuffle_pool = {}
|
||||
for i=1,20000 do
|
||||
global.shuffle_pool[i] = math.random(1, 4)
|
||||
end
|
||||
end
|
||||
make_maze(50, 50)
|
||||
reduce_walls()
|
||||
render()
|
||||
game.print(max)
|
||||
end
|
||||
|
||||
local function removeChunk(event)
|
||||
local surface = event.surface
|
||||
local tiles = {}
|
||||
for x = event.area.left_top.x, event.area.right_bottom.x do
|
||||
for y = event.area.left_top.y, event.area.right_bottom.y do
|
||||
table.insert(tiles, {name = "out-of-map", position = {x,y}})
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles)
|
||||
end
|
||||
|
||||
shape_module = true
|
||||
|
||||
first = true
|
||||
function gen(event)
|
||||
function run_shape_module(event)
|
||||
if first then
|
||||
first = false
|
||||
init()
|
||||
end
|
||||
local pos = event.area.left_top
|
||||
if (rects[pos.x + max/2 .. "/" .. pos.y + max/2] == nil) then
|
||||
if math.abs(pos.x) > 10000 or math.abs(pos.y) > 10000 or (global.rects[pos.x + global.max/2 .. "/" .. pos.y + global.max/2] == nil) then
|
||||
removeChunk(event)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -10,6 +10,7 @@ require "locale.gen_shared.simplex_noise"
|
||||
--shapes--
|
||||
--require "locale.gen_shape.right"
|
||||
--require "locale.gen_shape.up"
|
||||
require "locale.gen_shape.maze"
|
||||
--require "locale.gen_shape.spiral"
|
||||
--require "locale.gen_shape.spiral_tri"
|
||||
--require "locale.gen_shape.spiral2"
|
||||
|
Loading…
x
Reference in New Issue
Block a user