2017-12-08 09:45:57 +01:00
|
|
|
-- FUNCTIONS
|
|
|
|
local random = math.random
|
|
|
|
|
2017-12-06 17:00:51 +01:00
|
|
|
-- CONSTANTS
|
2017-12-07 23:58:29 +01:00
|
|
|
local UP = 1
|
|
|
|
local LEFT = 2
|
|
|
|
local RIGHT = 3
|
|
|
|
local DOWN = 4
|
2017-12-06 17:00:51 +01:00
|
|
|
|
2017-12-07 23:58:29 +01:00
|
|
|
local floor = {
|
|
|
|
center = nil,
|
|
|
|
top = nil,
|
|
|
|
bottom = nil,
|
|
|
|
left = nil,
|
|
|
|
right = nil,
|
|
|
|
topleft = nil,
|
|
|
|
topright = nil,
|
|
|
|
bottomleft = nil,
|
2017-12-08 09:45:57 +01:00
|
|
|
bottomright = nil
|
2017-12-07 23:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local wall = {
|
|
|
|
topleft = nil,
|
|
|
|
topright = nil,
|
|
|
|
bottomleft = nil,
|
|
|
|
bottomright = nil,
|
|
|
|
vertical = nil,
|
|
|
|
horizontal = nil
|
|
|
|
}
|
2017-12-06 16:02:50 +01:00
|
|
|
|
2018-03-20 21:54:57 +01:00
|
|
|
local pits = {
|
|
|
|
center = nil,
|
|
|
|
top = nil,
|
|
|
|
left = nil,
|
|
|
|
right = nil,
|
|
|
|
topleft = nil,
|
|
|
|
topright = nil,
|
|
|
|
}
|
|
|
|
|
2017-12-22 06:27:58 +01:00
|
|
|
local special = { level_exit = nil }
|
|
|
|
|
2017-12-08 09:45:57 +01:00
|
|
|
local floorDecor = { }
|
2017-12-11 11:53:18 +01:00
|
|
|
local lightDecor = { }
|
2017-12-08 09:45:57 +01:00
|
|
|
|
2017-12-08 14:40:33 +01:00
|
|
|
local function load_decor_textures()
|
2018-02-22 12:36:24 +01:00
|
|
|
td0 = add_texture(map, "Objects/Decor0.png")
|
|
|
|
td1 = add_texture(map, "Objects/Decor1.png")
|
2017-12-08 09:45:57 +01:00
|
|
|
|
|
|
|
-- Skulls
|
2017-12-10 19:51:24 +01:00
|
|
|
table.insert(floorDecor, { td0, td1, 0, 12 * 16, false, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 32, 12 * 16, false, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 64, 12 * 16, false, true })
|
|
|
|
table.insert(floorDecor, { td0, td1, 0, 13 * 16, false, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 32, 13 * 16, false, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 64, 13 * 16, false, true })
|
2017-12-08 09:45:57 +01:00
|
|
|
|
|
|
|
-- Bones
|
2017-12-10 19:51:24 +01:00
|
|
|
table.insert(floorDecor, { td0, td1, 16, 12 * 16, false, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 48, 12 * 16, false, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 16, 13 * 16, false, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 48, 13 * 16, false, false })
|
2017-12-08 09:45:57 +01:00
|
|
|
|
|
|
|
-- Urns
|
2018-07-31 14:25:29 +02:00
|
|
|
--table.insert(floorDecor, { td0, td1, 0 * 16, 48, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 1 * 16, 48, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 2 * 16, 48, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 3 * 16, 48, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 4 * 16, 48, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 5 * 16, 48, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 6 * 16, 48, false, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 7 * 16, 48, false, false })
|
2017-12-08 09:45:57 +01:00
|
|
|
|
2017-12-08 12:27:36 +01:00
|
|
|
-- Racks
|
2018-07-31 14:25:29 +02:00
|
|
|
--table.insert(floorDecor, { td0, td1, 0 * 16, 11 * 16, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 1 * 16, 11 * 16, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 2 * 16, 11 * 16, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 3 * 16, 11 * 16, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 4 * 16, 11 * 16, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 5 * 16, 11 * 16, true, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 6 * 16, 11 * 16, true, false })
|
2017-12-08 12:27:36 +01:00
|
|
|
|
2017-12-08 09:45:57 +01:00
|
|
|
-- Headstones
|
2017-12-10 19:51:24 +01:00
|
|
|
table.insert(floorDecor, { td0, td1, 0 * 16, 17 * 16, true, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 1 * 16, 17 * 16, true, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 2 * 16, 17 * 16, true, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 3 * 16, 17 * 16, true, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 4 * 16, 17 * 16, true, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 0 * 16, 18 * 16, true, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 1 * 16, 18 * 16, true, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 2 * 16, 18 * 16, true, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 3 * 16, 18 * 16, true, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 4 * 16, 18 * 16, true, false })
|
2017-12-08 14:40:33 +01:00
|
|
|
|
|
|
|
-- Altars
|
2017-12-10 19:51:24 +01:00
|
|
|
table.insert(floorDecor, { td0, td1, 0 * 16, 20 * 16, true, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 1 * 16, 20 * 16, true, false })
|
|
|
|
table.insert(floorDecor, { td0, td1, 2 * 16, 20 * 16, true, false })
|
2017-12-08 09:45:57 +01:00
|
|
|
|
|
|
|
-- Webs
|
2017-12-08 14:40:33 +01:00
|
|
|
--table.insert(floorDecor, { td0, td1, 0 * 16, 19 * 16, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 1 * 16, 19 * 16, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 2 * 16, 19 * 16, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 3 * 16, 19 * 16, false })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 4 * 16, 19 * 16, false })
|
|
|
|
|
|
|
|
-- Statues
|
|
|
|
--table.insert(floorDecor, { td0, td1, 3 * 16, 20 * 16, true })
|
|
|
|
--table.insert(floorDecor, { td0, td1, 4 * 16, 20 * 16, true })
|
2017-12-11 11:53:18 +01:00
|
|
|
|
|
|
|
lightDecor.candle0 = { td0, td1, 0, 8 * 16, false, true }
|
|
|
|
lightDecor.candle1 = { td0, td1, 16, 8 * 16, false, true }
|
|
|
|
lightDecor.candle2 = { td0, td1, 32, 8 * 16, true, true }
|
2017-12-08 14:40:33 +01:00
|
|
|
end
|
2017-12-08 09:45:57 +01:00
|
|
|
|
2017-12-22 06:27:58 +01:00
|
|
|
local function load_special_tiles()
|
2018-02-22 12:36:24 +01:00
|
|
|
tt = add_texture(map, "Objects/Tile.png")
|
2017-12-22 06:27:58 +01:00
|
|
|
special.level_exit = { tt, -1, 16, 16, false, true, true }
|
|
|
|
end
|
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
local function print_room(room)
|
|
|
|
print("ROOM:")
|
|
|
|
for j=0, 11 do
|
|
|
|
for i=0, 15 do
|
|
|
|
if room.tiles[i][j] then
|
|
|
|
io.write("o ")
|
|
|
|
else
|
|
|
|
io.write(". ")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
print("")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-10 19:51:24 +01:00
|
|
|
local function repack(data)
|
|
|
|
return {
|
|
|
|
textureIndex0 = data[1],
|
2017-12-22 06:27:58 +01:00
|
|
|
textureIndex1 = data[2] or -1,
|
2017-12-10 19:51:24 +01:00
|
|
|
tileClipX = data[3],
|
|
|
|
tileClipY = data[4],
|
|
|
|
isCollider = data[5] or false,
|
|
|
|
isLightSource = data[6] or false,
|
2017-12-22 06:27:58 +01:00
|
|
|
isLevelExit = data[7] or false,
|
2018-03-25 23:30:26 +02:00
|
|
|
isLethal = data[8] or false
|
2017-12-10 19:51:24 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-02-05 16:15:45 +01:00
|
|
|
local function check_add_decoration(map, x, y, data)
|
2018-02-16 09:10:05 +01:00
|
|
|
if tile_occupied(map, x, y) then
|
|
|
|
return false
|
|
|
|
end
|
2018-02-05 16:15:45 +01:00
|
|
|
add_decoration(map, x, y, repack(data))
|
2018-02-16 09:10:05 +01:00
|
|
|
return true
|
2018-02-05 16:15:45 +01:00
|
|
|
end
|
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
local function add_random_decor_to_room(room)
|
2017-12-08 09:45:57 +01:00
|
|
|
local decor_count = random(4) - 1
|
|
|
|
for i=1,decor_count do
|
2018-07-31 14:25:29 +02:00
|
|
|
x = random(11) + 1
|
|
|
|
y = random(8) + 1
|
|
|
|
if not room.decor[x][y] then
|
|
|
|
room.decor[x][y] = floorDecor[random(#floorDecor)]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if random(2) == 1 then
|
|
|
|
room.decor[4][3] = lightDecor.candle2
|
|
|
|
end
|
|
|
|
if random(2) == 1 then
|
|
|
|
room.decor[11][3] = lightDecor.candle2
|
|
|
|
end
|
|
|
|
if random(2) == 1 then
|
|
|
|
room.decor[4][9] = lightDecor.candle2
|
|
|
|
end
|
|
|
|
if random(2) == 1 then
|
|
|
|
room.decor[11][9] = lightDecor.candle2
|
2017-12-08 09:45:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
local function add_pits_to_room(room)
|
2018-03-20 21:54:57 +01:00
|
|
|
|
2018-03-25 23:30:26 +02:00
|
|
|
if CURRENT_LEVEL < 2 then
|
|
|
|
return
|
2018-05-15 14:15:51 +02:00
|
|
|
elseif random(5) ~= 1 then
|
2018-03-25 23:30:26 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-03-20 21:54:57 +01:00
|
|
|
local pitdata = read_file("pitlayouts.dat")
|
|
|
|
|
|
|
|
local cleanData = ""
|
|
|
|
for i=1, #pitdata do
|
|
|
|
local c = pitdata:sub(i+1, i+1)
|
|
|
|
if c == "#" or c == "-" then
|
|
|
|
cleanData = cleanData .. c
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local matrix = {}
|
|
|
|
for i=0, #cleanData-1 do
|
2018-03-25 23:30:26 +02:00
|
|
|
local c = cleanData:sub(i, i)
|
2018-03-20 21:54:57 +01:00
|
|
|
local col = i % 16
|
2018-03-26 13:53:45 +02:00
|
|
|
local row = (i - col)/16
|
|
|
|
local layout = 1 + (row - (row % 12))/12
|
|
|
|
local row = row % 12
|
|
|
|
if not matrix[layout] then matrix[layout] = {} end
|
|
|
|
if not matrix[layout][col] then matrix[layout][col] = {} end
|
2018-03-20 21:54:57 +01:00
|
|
|
if c == "#" then
|
2018-03-26 13:53:45 +02:00
|
|
|
matrix[layout][col][row] = true
|
2018-03-20 21:54:57 +01:00
|
|
|
elseif c == "-" then
|
2018-03-26 13:53:45 +02:00
|
|
|
matrix[layout][col][row] = false
|
2018-03-20 21:54:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-14 00:12:49 +02:00
|
|
|
matrix = matrix[random(#matrix)]
|
2018-03-25 23:30:26 +02:00
|
|
|
for i=2,13 do
|
|
|
|
for j=2,10 do
|
2018-07-31 14:25:29 +02:00
|
|
|
if matrix[i][j] then
|
|
|
|
room.decor[i][j] = nil
|
2018-03-20 21:54:57 +01:00
|
|
|
if not matrix[i-1][j-1] and not matrix[i+1][j-1] and matrix[i-1][j] and matrix[i+1][j] and matrix[i][j-1] then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = pits.innermid
|
2018-03-20 21:54:57 +01:00
|
|
|
elseif not matrix[i-1][j-1] and matrix[i-1][j] and matrix[i][j-1] then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = pits.innerleft
|
2018-03-20 21:54:57 +01:00
|
|
|
elseif not matrix[i+1][j-1] and matrix[i+1][j] and matrix[i][j-1] then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = pits.innerright
|
2018-03-20 21:54:57 +01:00
|
|
|
elseif not matrix[i-1][j] and not matrix[i][j-1] and not matrix[i+1][j] then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = pits.topcrevice
|
2018-03-20 21:54:57 +01:00
|
|
|
elseif not matrix[i-1][j] and not matrix[i+1][j] then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = pits.bottomcrevice
|
2018-03-20 21:54:57 +01:00
|
|
|
elseif not matrix[i-1][j] and not matrix[i][j-1] then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = pits.topleft
|
2018-03-20 21:54:57 +01:00
|
|
|
elseif not matrix[i+1][j] and not matrix[i][j-1] then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = pits.topright
|
2018-03-20 21:54:57 +01:00
|
|
|
elseif not matrix[i-1][j] then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = pits.left
|
2018-03-20 21:54:57 +01:00
|
|
|
elseif not matrix[i+1][j] then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = pits.right
|
2018-03-20 21:54:57 +01:00
|
|
|
elseif not matrix[i][j-1] then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = pits.top
|
2018-03-20 21:54:57 +01:00
|
|
|
else
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = pits.center
|
2018-03-20 21:54:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
local function add_tiles_to_room (room)
|
2017-12-06 16:02:50 +01:00
|
|
|
for i=0,15 do
|
|
|
|
for j=0,11 do
|
|
|
|
if (i >= 1 and i <= 14 and j >= 1 and j <= 10) then
|
|
|
|
if (i == 1 and j == 1) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = floor.topleft
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (i == 14 and j == 1) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = floor.topright
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (i == 1 and j == 10) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = floor.bottomleft
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (i == 14 and j == 10) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = floor.bottomright
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (i == 1) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = floor.left
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (i == 14) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = floor.right
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (j == 1) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = floor.top
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (j == 10) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = floor.bottom
|
2017-12-06 16:02:50 +01:00
|
|
|
else
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = floor.center
|
2017-12-06 16:02:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
local function add_walls_to_room (room)
|
2017-12-06 16:02:50 +01:00
|
|
|
for i=0,15 do
|
|
|
|
for j=0,11 do
|
|
|
|
if (i == 0 and j == 0) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = wall.topleft
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (i == 15 and j == 0) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = wall.topright
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (i == 0 and j == 11) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = wall.bottomleft
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (i == 15 and j == 11) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = wall.bottomright
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (i == 0 or i == 15) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = wall.vertical
|
2017-12-06 16:02:50 +01:00
|
|
|
elseif (j == 0 or j == 11) then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[i][j] = wall.horizontal
|
2017-12-06 16:02:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
local function build_vert_center_coridoor(room, offset)
|
|
|
|
for i=0,4 do
|
|
|
|
room.tiles[6][offset+i] = wall.vertical
|
|
|
|
room.tiles[7][offset+i] = floor.center
|
|
|
|
room.tiles[8][offset+i] = floor.center
|
|
|
|
room.tiles[9][offset+i] = wall.vertical
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
2017-12-11 11:53:18 +01:00
|
|
|
if random(2) == 1 then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.decor[6][offset+2] = lightDecor.candle1
|
2017-12-11 11:53:18 +01:00
|
|
|
end
|
|
|
|
if random(2) == 1 then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.decor[6][offset+2] = lightDecor.candle1
|
2017-12-11 11:53:18 +01:00
|
|
|
end
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
local function build_horiz_center_coridoor(room, offset)
|
|
|
|
info("Building horizontal corrdior: " .. offset)
|
2017-12-07 23:58:29 +01:00
|
|
|
for i=0,6 do
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[offset+i][4] = wall.horizontal
|
|
|
|
room.tiles[offset+i][5] = floor.center
|
|
|
|
room.tiles[offset+i][6] = floor.center
|
|
|
|
room.tiles[offset+i][7] = wall.horizontal
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
2017-12-11 11:53:18 +01:00
|
|
|
if random(2) == 1 then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.decor[offset+3][4] = lightDecor.candle1
|
2017-12-11 11:53:18 +01:00
|
|
|
end
|
|
|
|
if random(2) == 1 then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.decor[offset+3][7] = lightDecor.candle1
|
2017-12-11 11:53:18 +01:00
|
|
|
end
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
local function build_center_corner_walls(room, exits)
|
2017-12-07 23:58:29 +01:00
|
|
|
if exits.down then
|
|
|
|
if exits.left then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[6][7] = wall.topright
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
|
|
|
if exits.right then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[9][7] = wall.topleft
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if not exits.left then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[6][7] = wall.bottomleft
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
|
|
|
if not exits.right then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[9][7] = wall.bottomright
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if exits.up then
|
|
|
|
if exits.left then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[6][4] = wall.bottomright
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
|
|
|
if exits.right then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[9][4] = wall.bottomleft
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if not exits.left then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[6][4] = wall.topleft
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
|
|
|
if not exits.right then
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[9][4] = wall.topright
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
2017-12-06 16:02:50 +01:00
|
|
|
end
|
|
|
|
end
|
2017-12-07 23:58:29 +01:00
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
local function add_exits_to_room(room)
|
|
|
|
for _,direction in ipairs(room.exits) do
|
|
|
|
if direction == UP then
|
|
|
|
room.tiles[6][0] = wall.bottomright
|
|
|
|
room.tiles[7][0] = floor.singleleft
|
|
|
|
room.tiles[8][0] = floor.singleright
|
|
|
|
room.tiles[9][0] = wall.bottomleft
|
|
|
|
elseif direction == LEFT then
|
|
|
|
room.tiles[0][4] = wall.bottomright
|
|
|
|
room.tiles[0][5] = floor.singletop
|
|
|
|
room.tiles[0][6] = floor.singlebottom
|
|
|
|
room.tiles[0][7] = wall.topright
|
|
|
|
elseif direction == RIGHT then
|
|
|
|
room.tiles[15][4] = wall.bottomleft
|
|
|
|
room.tiles[15][5] = floor.singletop
|
|
|
|
room.tiles[15][6] = floor.singlebottom
|
|
|
|
room.tiles[15][7] = wall.topleft
|
|
|
|
elseif direction == DOWN then
|
|
|
|
room.tiles[6][11] = wall.topright
|
|
|
|
room.tiles[7][11] = floor.singleleft
|
|
|
|
room.tiles[8][11] = floor.singleright
|
|
|
|
room.tiles[9][11] = wall.topleft
|
|
|
|
end
|
|
|
|
end
|
2018-02-09 13:27:25 +01:00
|
|
|
end
|
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
local function build_coridoor_room(room)
|
2017-12-07 23:58:29 +01:00
|
|
|
local exits = {
|
|
|
|
up = false,
|
|
|
|
down = false,
|
|
|
|
left = false,
|
|
|
|
right = false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _,exit in ipairs(room.exits) do
|
|
|
|
if UP == exit then exits.up = true
|
|
|
|
elseif DOWN == exit then exits.down = true
|
|
|
|
elseif LEFT == exit then exits.left = true
|
|
|
|
elseif RIGHT == exit then exits.right = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Fill the center
|
2018-07-31 14:25:29 +02:00
|
|
|
room.tiles[6][5] = wall.vertical
|
|
|
|
room.tiles[6][6] = wall.vertical
|
|
|
|
room.tiles[7][4] = wall.horizontal
|
|
|
|
room.tiles[7][5] = floor.center
|
|
|
|
room.tiles[7][6] = floor.center
|
|
|
|
room.tiles[7][7] = wall.horizontal
|
|
|
|
room.tiles[8][4] = wall.horizontal
|
|
|
|
room.tiles[8][5] = floor.center
|
|
|
|
room.tiles[8][6] = floor.center
|
|
|
|
room.tiles[8][7] = wall.horizontal
|
|
|
|
room.tiles[9][5] = wall.vertical
|
|
|
|
room.tiles[9][6] = wall.vertical
|
2017-12-07 23:58:29 +01:00
|
|
|
|
|
|
|
-- Build the coridoors
|
2018-07-31 14:25:29 +02:00
|
|
|
if exits.down then build_vert_center_coridoor(room, 7) end
|
|
|
|
if exits.up then build_vert_center_coridoor(room, 0) end
|
|
|
|
if exits.left then build_horiz_center_coridoor(room, 0) end
|
|
|
|
if exits.right then build_horiz_center_coridoor(room, 9) end
|
2017-12-07 23:58:29 +01:00
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
build_center_corner_walls(room, exits)
|
2017-12-07 23:58:29 +01:00
|
|
|
end
|
2017-12-11 20:07:05 +01:00
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
local function add_level_exit(room)
|
|
|
|
success = false
|
|
|
|
while not success do
|
|
|
|
x = random(14)
|
|
|
|
y = random(10)
|
|
|
|
if not room.decor[x][y] then
|
|
|
|
success = true
|
|
|
|
room.tiles[x][y] = special.level_exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function build_normal_room(room)
|
|
|
|
add_tiles_to_room(room)
|
|
|
|
add_random_decor_to_room(room)
|
|
|
|
add_walls_to_room(room)
|
|
|
|
add_exits_to_room(room)
|
|
|
|
add_pits_to_room(room)
|
|
|
|
|
|
|
|
if room.goal then
|
|
|
|
add_level_exit(room)
|
|
|
|
end
|
|
|
|
|
|
|
|
if CURRENT_LEVEL > 3 and random(10) == 1 then
|
|
|
|
directions = { "LEFT", "RIGHT", "UP", "DOWN" }
|
|
|
|
room.modifier.type = "WINDY"
|
|
|
|
room.modifier.arg = directions[random(#directions)]
|
|
|
|
end
|
|
|
|
|
|
|
|
return room
|
|
|
|
end
|
|
|
|
|
|
|
|
local module = {}
|
|
|
|
|
|
|
|
function module.add_exit(room, direction)
|
|
|
|
if direction > 4 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
table.insert(room.exits, direction)
|
|
|
|
end
|
|
|
|
|
|
|
|
function module.add_full_lighting(room)
|
|
|
|
room.decor[4][3] = lightDecor.candle2
|
|
|
|
room.decor[11][3] = lightDecor.candle2
|
|
|
|
room.decor[4][9] = lightDecor.candle2
|
|
|
|
room.decor[11][9] = lightDecor.candle2
|
|
|
|
end
|
|
|
|
|
|
|
|
function module.create_empty_room()
|
|
|
|
room = {
|
2017-12-11 20:07:05 +01:00
|
|
|
exits = {},
|
|
|
|
active = false,
|
|
|
|
goal = false,
|
|
|
|
path_dir = 0,
|
2018-07-31 14:25:29 +02:00
|
|
|
type = "room",
|
|
|
|
tiles = {},
|
|
|
|
decor = {},
|
|
|
|
modifier = {
|
|
|
|
type = nil,
|
|
|
|
arg = nil
|
|
|
|
},
|
|
|
|
monsters = {}
|
2017-12-11 20:07:05 +01:00
|
|
|
}
|
2018-07-31 14:25:29 +02:00
|
|
|
for i=0,15 do
|
|
|
|
room.tiles[i] = {}
|
|
|
|
room.decor[i] = {}
|
|
|
|
room.monsters[i] = {}
|
|
|
|
for j=0,11 do
|
|
|
|
room.tiles[i][j] = nil
|
|
|
|
room.decor[i][j] = nil
|
|
|
|
room.monsters[i][j] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return room
|
2017-12-11 20:07:05 +01:00
|
|
|
end
|
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
function module.build_room(room)
|
|
|
|
if room.type == "coridoor" then
|
|
|
|
build_coridoor_room(room)
|
|
|
|
else
|
|
|
|
build_normal_room(room)
|
2017-12-22 06:27:58 +01:00
|
|
|
end
|
2018-07-31 14:25:29 +02:00
|
|
|
end
|
2018-03-15 16:30:41 +01:00
|
|
|
|
2018-07-31 14:25:29 +02:00
|
|
|
function module.load_room(map, room)
|
|
|
|
for i=0, 15 do
|
|
|
|
for j=0, 11 do
|
|
|
|
if room.tiles[i][j] then
|
|
|
|
add_tile(map, i, j, repack(room.tiles[i][j]))
|
|
|
|
end
|
|
|
|
if room.decor[i][j] then
|
|
|
|
add_decoration(map, i, j, repack(room.decor[i][j]))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if room.modifier.type then
|
|
|
|
set_modifier(map, room.modifier.type, room.modifier.arg)
|
2018-03-15 16:30:41 +01:00
|
|
|
end
|
2017-12-11 20:07:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function module.load_textures(map)
|
2018-02-22 12:36:24 +01:00
|
|
|
t_floor = add_texture(map, "Objects/Floor.png")
|
|
|
|
t_wall = add_texture(map, "Objects/Wall.png")
|
2018-03-20 21:54:57 +01:00
|
|
|
t_pit0 = add_texture(map, "Objects/Pit0.png")
|
|
|
|
t_pit1 = add_texture(map, "Objects/Pit1.png")
|
2017-12-11 20:07:05 +01:00
|
|
|
|
|
|
|
math.randomseed(os.time())
|
|
|
|
local xo = (random(3) - 1) * 112
|
2018-03-20 21:54:57 +01:00
|
|
|
local yo = (random(8)) * 48
|
2017-12-11 20:07:05 +01:00
|
|
|
|
|
|
|
floor.center = { t_floor, -1, xo + 16, yo + 16, false }
|
|
|
|
floor.top = { t_floor, -1, xo + 16, yo + 0, false }
|
|
|
|
floor.bottom = { t_floor, -1, xo + 16, yo + 32, false }
|
|
|
|
floor.left = { t_floor, -1, xo + 0, yo + 16, false }
|
|
|
|
floor.right = { t_floor, -1, xo + 32, yo + 16, false }
|
|
|
|
floor.topleft = { t_floor, -1, xo + 0, yo + 0, false }
|
|
|
|
floor.topright = { t_floor, -1, xo + 32, yo + 0, false }
|
|
|
|
floor.bottomleft = { t_floor, -1, xo + 0, yo + 32, false }
|
|
|
|
floor.bottomright = { t_floor, -1, xo + 32, yo + 32, false }
|
|
|
|
floor.singletop = { t_floor, -1, xo + 48, yo + 0, false }
|
|
|
|
floor.singlebottom = { t_floor, -1, xo + 48, yo + 32, false }
|
|
|
|
floor.singleleft = { t_floor, -1, xo + 64, yo + 16, false }
|
|
|
|
floor.singleright = { t_floor, -1, xo + 96, yo + 16, false }
|
|
|
|
|
2018-03-20 21:54:57 +01:00
|
|
|
local pit_yo = (random(5) + random(3)) * (16 * 2)
|
2018-03-25 23:30:26 +02:00
|
|
|
pits.topleft = { t_pit0, t_pit1, 0, pit_yo, false, false, false, true }
|
|
|
|
pits.top = { t_pit0, t_pit1, 16, pit_yo, false, false, false, true }
|
|
|
|
pits.topright = { t_pit0, t_pit1, 32, pit_yo, false, false, false, true }
|
|
|
|
pits.left = { t_pit0, t_pit1, 0, pit_yo + 16, false, false, false, true }
|
|
|
|
pits.center = { t_pit0, t_pit1, 16, pit_yo + 16, false, false, false, true }
|
|
|
|
pits.right = { t_pit0, t_pit1, 32, pit_yo + 16, false, false, false, true }
|
|
|
|
pits.innerleft = { t_pit0, t_pit1, 80, pit_yo, false, false, false, true }
|
|
|
|
pits.innermid = { t_pit0, t_pit1, 96, pit_yo, false, false, false, true }
|
|
|
|
pits.innerright = { t_pit0, t_pit1, 112, pit_yo, false, false, false, true }
|
|
|
|
pits.topcrevice = { t_pit0, t_pit1, 64, pit_yo, false, false, false, true }
|
|
|
|
pits.bottomcrevice = { t_pit0, t_pit1, 64, pit_yo + 16, false, false, false, true }
|
2018-03-20 21:54:57 +01:00
|
|
|
|
2017-12-11 20:07:05 +01:00
|
|
|
wall.topleft = { t_wall, -1, xo + 0, yo + 0, true }
|
|
|
|
wall.topright = { t_wall, -1, xo + 32, yo + 0, true }
|
|
|
|
wall.bottomleft = { t_wall, -1, xo + 0, yo + 32, true }
|
|
|
|
wall.bottomright = { t_wall, -1, xo + 32, yo + 32, true }
|
|
|
|
wall.vertical = { t_wall, -1, xo + 0, yo + 16, true }
|
|
|
|
wall.horizontal = { t_wall, -1, xo + 16, yo + 0, true }
|
|
|
|
|
|
|
|
load_decor_textures()
|
2017-12-22 06:27:58 +01:00
|
|
|
load_special_tiles()
|
2017-12-11 20:07:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return module
|