mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-02-07 13:31:54 +02:00
Added maze
This commit is contained in:
parent
f582cb862c
commit
c2c443e2ce
@ -1,11 +1,10 @@
|
|||||||
local wall_thickness = 1
|
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 wall_delta = math.floor((cell_size-wall_thickness)/2)
|
||||||
local chunk_size = 32
|
local chunk_size = 32
|
||||||
|
|
||||||
rects = {}
|
|
||||||
pixels = {}
|
pixels = {}
|
||||||
cells = {}
|
cells = {}
|
||||||
function add_tile(x, y, width, height, add_cell)
|
function add_tile(x, y, width, height, add_cell)
|
||||||
@ -21,22 +20,30 @@ function add_tile(x, y, width, height, add_cell)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local max = 0
|
global.max = 0
|
||||||
function render()
|
function render()
|
||||||
for x,_ in pairs(pixels) do
|
for x,_ in pairs(pixels) do
|
||||||
for y,_ in pairs(pixels[x]) do
|
for y,_ in pairs(pixels[x]) do
|
||||||
if y * 32 > max and y % 2 == 0 then
|
if y * 32 > global.max and y % 2 == 0 then
|
||||||
max = y * 32
|
global.max = y * 32
|
||||||
end
|
end
|
||||||
rects[x*32 .. "/" .. y*32] = 1
|
global.rects[x*32 .. "/" .. y*32] = 1
|
||||||
end
|
end
|
||||||
end
|
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)
|
function shuffle(t)
|
||||||
for i = 1, #t - 1 do
|
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]
|
t[i], t[r] = t[r], t[i]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -86,8 +93,7 @@ function make_maze(w, h)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
walk(global.walk_seed_w, global.walk_seed_h)
|
||||||
walk(math.random(1, w)*2, math.random(1, h)*2)
|
|
||||||
|
|
||||||
local s = {}
|
local s = {}
|
||||||
for i = 1, h*2+1 do
|
for i = 1, h*2+1 do
|
||||||
@ -119,22 +125,41 @@ local function reduce_walls()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function init()
|
function init()
|
||||||
game.print(game.tick)
|
if not global.walk_seed_w then global.walk_seed_w = math.random(1, 50)*2 end
|
||||||
-- math.randomseed( 78579837297 )
|
if not global.rects then global.rects = {} end
|
||||||
make_maze(40, 40)
|
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()
|
reduce_walls()
|
||||||
render()
|
render()
|
||||||
game.print(max)
|
|
||||||
end
|
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
|
first = true
|
||||||
function gen(event)
|
function run_shape_module(event)
|
||||||
if first then
|
if first then
|
||||||
first = false
|
first = false
|
||||||
init()
|
init()
|
||||||
end
|
end
|
||||||
local pos = event.area.left_top
|
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)
|
removeChunk(event)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ require "locale.gen_shared.simplex_noise"
|
|||||||
--shapes--
|
--shapes--
|
||||||
--require "locale.gen_shape.right"
|
--require "locale.gen_shape.right"
|
||||||
--require "locale.gen_shape.up"
|
--require "locale.gen_shape.up"
|
||||||
|
require "locale.gen_shape.maze"
|
||||||
--require "locale.gen_shape.spiral"
|
--require "locale.gen_shape.spiral"
|
||||||
--require "locale.gen_shape.spiral_tri"
|
--require "locale.gen_shape.spiral_tri"
|
||||||
--require "locale.gen_shape.spiral2"
|
--require "locale.gen_shape.spiral2"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user