Nicer wall decorations on interior walls

This commit is contained in:
Linus Probert 2019-03-08 16:58:25 +01:00
parent 8c9622d6bd
commit 7ab5ece83b
1 changed files with 81 additions and 25 deletions

View File

@ -3,7 +3,7 @@ local pits = {}
local walls = {} local walls = {}
local fences = {} local fences = {}
local lights = {} local lights = {}
local decor = {} local walldecor = {}
local function readLayoutFile(file) local function readLayoutFile(file)
local layoutfile = read_file(file) local layoutfile = read_file(file)
@ -58,40 +58,58 @@ local function getTileStateFor(matrix, i, j, c)
return above, below, left, right, above_left, above_right, below_left, below_right return above, below, left, right, above_left, above_right, below_left, below_right
end end
local function setBlockTile(room, matrix, i, j, tiles, char, decorTiles) local function getRandomWallDecorFrom(wallDecorations)
return wallDecorations[random(#wallDecorations)]
end
local function setBlockTile(room, matrix, i, j, tiles, char, decor)
local above, below, left, right, above_left, above_right, below_left, below_right = getTileStateFor(matrix, i, j, char); local above, below, left, right, above_left, above_right, below_left, below_right = getTileStateFor(matrix, i, j, char);
room.decor[i][j] = nil room.decor[i][j] = nil
local tile = nil local tile = nil
local decorTile = nil
if above and below and left and right then if above and below and left and right then
tile = tiles.cross tile = tiles.cross
elseif not above and below and left and right then elseif not above and below and left and right then
tile = tiles.top_t tile = tiles.top_t
elseif not below and above and left and right then elseif not below and above and left and right then
tile = tiles.bottom_t tile = tiles.bottom_t
decorTile = getRandomWallDecorFrom(walldecor.bottom_t)
elseif not left and above and below and right then elseif not left and above and below and right then
tile = tiles.left_t tile = tiles.left_t
decorTile = getRandomWallDecorFrom(walldecor.left_t)
elseif not right and above and below and left then elseif not right and above and below and left then
tile = tiles.right_t tile = tiles.right_t
decorTile = getRandomWallDecorFrom(walldecor.right_t)
elseif not above and not left and right and below then elseif not above and not left and right and below then
tile = tiles.topleft tile = tiles.topleft
decorTile = getRandomWallDecorFrom(walldecor.topleft)
elseif not above and not right and left and below then elseif not above and not right and left and below then
tile = tiles.topright tile = tiles.topright
decorTile = getRandomWallDecorFrom(walldecor.topright)
elseif not below and not left and above and right then elseif not below and not left and above and right then
tile = tiles.bottomleft tile = tiles.bottomleft
decorTile = getRandomWallDecorFrom(walldecor.bottomleft)
elseif not below and not right and above and left then elseif not below and not right and above and left then
tile = tiles.bottomright tile = tiles.bottomright
decorTile = getRandomWallDecorFrom(walldecor.bottomright)
elseif not left and not right and below then elseif not left and not right and below then
tile = tiles.left tile = tiles.left
decorTile = getRandomWallDecorFrom(walldecor.left)
elseif not above and not below and (left or right) then elseif not above and not below and (left or right) then
tile = tiles.top tile = tiles.top
decorTile = getRandomWallDecorFrom(walldecor.top)
else else
tile = tiles.single tile = tiles.single
decorTile = getRandomWallDecorFrom(walldecor.single)
end end
if decorTiles then if decor then
room.decor[i][j] = tile room.decor[i][j] = tile
else else
room.tiles[i][j] = tile room.tiles[i][j] = tile
if random(8) == 1 then
room.decor[i][j] = decorTile
end
end end
end end
@ -188,22 +206,63 @@ function module.load_textures(map, wall_xoffset, wall_yoffset)
candle1 = { t_decor0, t_decor1, 1 * 16, 8 * 16, true, true }, candle1 = { t_decor0, t_decor1, 1 * 16, 8 * 16, true, true },
candle2 = { t_decor0, t_decor1, 5 * 16, 8 * 16, true, false }, candle2 = { t_decor0, t_decor1, 5 * 16, 8 * 16, true, false },
} }
walldecor = {
decor = { topleft = {
-- Webs { t_decor0, nil, 2 * 16, 2 * 16, false },
{ t_decor0, nil, 0 * 16, 19 * 16, false }, { t_decor0, nil, 6 * 16, 2 * 16, false },
{ t_decor0, nil, 1 * 16, 19 * 16, false }, { t_decor0, nil, 7 * 16, 2 * 16, false },
{ t_decor0, nil, 2 * 16, 19 * 16, false }, },
{ t_decor0, nil, 3 * 16, 19 * 16, false }, top = {
{ t_decor0, nil, 4 * 16, 19 * 16, false }, { t_decor0, nil, 0 * 16, 2 * 16, false },
{ t_decor0, nil, 1 * 16, 2 * 16, false },
-- Cracks { t_decor0, nil, 4 * 16, 2 * 16, false },
{ t_decor0, nil, 0 * 16, 2 * 16, false }, { t_decor0, nil, 5 * 16, 2 * 16, false },
{ t_decor0, nil, 1 * 16, 2 * 16, false }, },
single = {
-- Vines { t_decor0, nil, 0 * 16, 2 * 16, false },
{ t_decor0, nil, 4 * 16, 2 * 16, false }, { t_decor0, nil, 1 * 16, 2 * 16, false },
{ t_decor0, nil, 5 * 16, 2 * 16, false }, { t_decor0, nil, 4 * 16, 2 * 16, false },
{ t_decor0, nil, 5 * 16, 2 * 16, false },
},
topright = {
{ t_decor0, nil, 3 * 16, 2 * 16, false },
},
left = {
{ t_decor0, nil, 2 * 16, 2 * 16, false },
{ t_decor0, nil, 3 * 16, 2 * 16, false },
{ t_decor0, nil, 6 * 16, 2 * 16, false },
{ t_decor0, nil, 7 * 16, 2 * 16, false },
},
bottomleft = {
{ t_decor0, nil, 0 * 16, 2 * 16, false },
{ t_decor0, nil, 1 * 16, 2 * 16, false },
{ t_decor0, nil, 2 * 16, 2 * 16, false },
{ t_decor0, nil, 4 * 16, 2 * 16, false },
{ t_decor0, nil, 5 * 16, 2 * 16, false },
{ t_decor0, nil, 6 * 16, 2 * 16, false },
{ t_decor0, nil, 7 * 16, 2 * 16, false },
},
bottomright = {
{ t_decor0, nil, 0 * 16, 2 * 16, false },
{ t_decor0, nil, 1 * 16, 2 * 16, false },
{ t_decor0, nil, 3 * 16, 2 * 16, false },
{ t_decor0, nil, 4 * 16, 2 * 16, false },
{ t_decor0, nil, 5 * 16, 2 * 16, false },
},
left_t = {
{ t_decor0, nil, 2 * 16, 2 * 16, false },
{ t_decor0, nil, 6 * 16, 2 * 16, false },
{ t_decor0, nil, 7 * 16, 2 * 16, false },
},
right_t = {
{ t_decor0, nil, 3 * 16, 2 * 16, false },
},
bottom_t = {
{ t_decor0, nil, 0 * 16, 2 * 16, false },
{ t_decor0, nil, 1 * 16, 2 * 16, false },
{ t_decor0, nil, 4 * 16, 2 * 16, false },
{ t_decor0, nil, 5 * 16, 2 * 16, false },
},
} }
end end
@ -244,9 +303,6 @@ function draw_layout_to_room(room, matrix, roomx, roomy)
setPitTile(room, matrix, i, j); setPitTile(room, matrix, i, j);
elseif matrix[i][j] == "#" then elseif matrix[i][j] == "#" then
setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/"}, false) setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/"}, false)
if (random(4) == 1) then
room.decor[i][j] = decor[random(#decor)]
end
elseif matrix[i][j] == "\"" then elseif matrix[i][j] == "\"" then
setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/"}, false) setBlockTile(room, matrix, i, j, walls, {"#", "\"", "/"}, false)
room.decor[i][j] = lights.candle1 room.decor[i][j] = lights.candle1
@ -268,7 +324,7 @@ function draw_layout_to_room(room, matrix, roomx, roomy)
end end
end end
function pickARoom(matrix) function pickALayout(matrix)
-- Chose a random layout -- Chose a random layout
if random(2) == 1 then if random(2) == 1 then
return matrix[random(#matrix)] return matrix[random(#matrix)]
@ -282,7 +338,7 @@ function module.add_walls_to_room(room)
return false return false
end end
draw_layout_to_room(room, pickARoom(readLayoutFile("walllayouts.dat"))) draw_layout_to_room(room, pickALayout(readLayoutFile("walllayouts.dat")))
return true return true
end end
@ -291,7 +347,7 @@ function module.add_pits_to_room(room)
return false return false
end end
draw_layout_to_room(room, pickARoom(readLayoutFile("pitlayouts.dat"))) draw_layout_to_room(room, pickALayout(readLayoutFile("pitlayouts.dat")))
return true return true
end end