Adds complete rewrite of lua scripts
Lua scripts now build an in memory structure of all the rooms and their contents before loading this data into the game. This enables better possibilities to prevent monsters from spawning in bad places. Monsters can now also spawn in coridoor rooms.
This commit is contained in:
parent
18e70221fa
commit
b3b8208b11
|
@ -17,7 +17,7 @@ local function matrix_coverage (matrix)
|
|||
local cov = 0
|
||||
for i=1,10 do
|
||||
for j=1,10 do
|
||||
if matrix[i][j].active then cov = cov + 1 end
|
||||
if matrix[i][j] then cov = cov + 1 end
|
||||
end
|
||||
end
|
||||
return cov
|
||||
|
@ -36,7 +36,7 @@ local function generate_path ()
|
|||
for i=1,10 do
|
||||
map_matrix[i] = {}
|
||||
for j=1,10 do
|
||||
map_matrix[i][j] = room_builder.create_room()
|
||||
map_matrix[i][j] = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,7 +47,10 @@ local function generate_path ()
|
|||
local direction = 0
|
||||
local lastDirection = 0
|
||||
local coridoor_count = 0
|
||||
local coverage = 10
|
||||
local coverage = 9 + CURRENT_LEVEL
|
||||
|
||||
-- Create the first room
|
||||
map_matrix[cx][cy] = room_builder.create_empty_room()
|
||||
|
||||
while matrix_coverage(map_matrix) < coverage do
|
||||
local direction = random(4)
|
||||
|
@ -60,8 +63,6 @@ local function generate_path ()
|
|||
direction = random(4)
|
||||
end
|
||||
|
||||
map_matrix[cx][cy].active = true
|
||||
|
||||
if coridoor_count < coverage/3 then
|
||||
if random(3) == 1 and (cx > 1 or cy > 1) then
|
||||
map_matrix[cx][cy].type = "coridoor"
|
||||
|
@ -69,49 +70,56 @@ local function generate_path ()
|
|||
end
|
||||
end
|
||||
|
||||
valid_direction = false
|
||||
if direction == UP and cy > 1 then -- UP
|
||||
table.insert(map_matrix[cx][cy].exits, direction)
|
||||
room_builder.add_exit(map_matrix[cx][cy], direction)
|
||||
map_matrix[cx][cy].path_dir = direction
|
||||
cy = cy - 1;
|
||||
table.insert(map_matrix[cx][cy].exits, reverse_direction(direction))
|
||||
cy = cy - 1
|
||||
valid_direction = true
|
||||
elseif direction == LEFT and cx > 1 then -- LEFT
|
||||
table.insert(map_matrix[cx][cy].exits, direction)
|
||||
room_builder.add_exit(map_matrix[cx][cy], direction)
|
||||
map_matrix[cx][cy].path_dir = direction
|
||||
cx = cx - 1;
|
||||
table.insert(map_matrix[cx][cy].exits, reverse_direction(direction))
|
||||
cx = cx - 1
|
||||
valid_direction = true
|
||||
elseif direction == RIGHT and cx < 10 then -- RIGHT
|
||||
table.insert(map_matrix[cx][cy].exits, direction)
|
||||
room_builder.add_exit(map_matrix[cx][cy], direction)
|
||||
map_matrix[cx][cy].path_dir = direction
|
||||
cx = cx + 1;
|
||||
table.insert(map_matrix[cx][cy].exits, reverse_direction(direction))
|
||||
cx = cx + 1
|
||||
valid_direction = true
|
||||
elseif direction == DOWN and cy < 10 then -- DOWN
|
||||
table.insert(map_matrix[cx][cy].exits, direction)
|
||||
room_builder.add_exit(map_matrix[cx][cy], direction)
|
||||
map_matrix[cx][cy].path_dir = direction
|
||||
cy = cy + 1;
|
||||
table.insert(map_matrix[cx][cy].exits, reverse_direction(direction))
|
||||
cy = cy + 1
|
||||
valid_direction = true
|
||||
end
|
||||
|
||||
-- Create the next room and add the reverse exit
|
||||
-- if a valid direction was found
|
||||
if valid_direction then
|
||||
if not map_matrix[cx][cy] then
|
||||
map_matrix[cx][cy] = room_builder.create_empty_room()
|
||||
end
|
||||
room_builder.add_exit(map_matrix[cx][cy], reverse_direction(direction))
|
||||
end
|
||||
lastDirection = direction
|
||||
end
|
||||
|
||||
-- Last room rules
|
||||
map_matrix[cx][cy].active = true
|
||||
map_matrix[cx][cy].goal = true
|
||||
map_matrix[cx][cy].type = "room"
|
||||
|
||||
return map_matrix;
|
||||
end
|
||||
|
||||
local function print_matrix(matrix)
|
||||
-- Build all the rooms
|
||||
for i=1,10 do
|
||||
for j=1,10 do
|
||||
if not map_matrix[j][i].goal then
|
||||
io.write(map_matrix[j][i].path_dir .. " ")
|
||||
else
|
||||
io.write("G ")
|
||||
room = map_matrix[i][j]
|
||||
if room then
|
||||
room_builder.build_room(room)
|
||||
monster_gen.add_monsters_to_room(room, i-1, j-1)
|
||||
end
|
||||
end
|
||||
io.write("\n")
|
||||
end
|
||||
|
||||
return map_matrix;
|
||||
end
|
||||
-- END FUNCTIONS
|
||||
|
||||
|
@ -126,14 +134,10 @@ local map_matrix = generate_path()
|
|||
for i=1,10 do
|
||||
for j=1,10 do
|
||||
local room = map_matrix[i][j]
|
||||
if room.active then
|
||||
if room then
|
||||
set_current_room(map, i-1, j-1);
|
||||
if room.type == "room" then
|
||||
room_builder.build_square_room(map, room)
|
||||
monster_gen.add_monster_to_room(map, i-1, j-1);
|
||||
elseif room.type == "coridoor" then
|
||||
room_builder.build_coridoor_room(map, room)
|
||||
end
|
||||
room_builder.load_room(map, room)
|
||||
monster_gen.load_monsters(map, room.monsters)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -61,23 +61,23 @@ local function load_decor_textures()
|
|||
table.insert(floorDecor, { td0, td1, 48, 13 * 16, false, false })
|
||||
|
||||
-- Urns
|
||||
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 })
|
||||
--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 })
|
||||
|
||||
-- Racks
|
||||
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 })
|
||||
--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 })
|
||||
|
||||
-- Headstones
|
||||
table.insert(floorDecor, { td0, td1, 0 * 16, 17 * 16, true, false })
|
||||
|
@ -117,6 +117,20 @@ local function load_special_tiles()
|
|||
special.level_exit = { tt, -1, 16, 16, false, true, true }
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
local function repack(data)
|
||||
return {
|
||||
textureIndex0 = data[1],
|
||||
|
@ -138,22 +152,31 @@ local function check_add_decoration(map, x, y, data)
|
|||
return true
|
||||
end
|
||||
|
||||
local function check_add_tile(map, x, y, data)
|
||||
if tile_occupied(map, x, y) then
|
||||
return false
|
||||
end
|
||||
add_tile(map, x, y, repack(data))
|
||||
return true
|
||||
end
|
||||
|
||||
local function add_random_decor_to_room(map)
|
||||
local function add_random_decor_to_room(room)
|
||||
local decor_count = random(4) - 1
|
||||
for i=1,decor_count do
|
||||
check_add_decoration(map, random(11)+1, random(8)+1, floorDecor[random(#floorDecor)])
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
local function add_pits_to_room(map)
|
||||
local function add_pits_to_room(room)
|
||||
|
||||
if CURRENT_LEVEL < 2 then
|
||||
return
|
||||
|
@ -171,7 +194,6 @@ local function add_pits_to_room(map)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
local matrix = {}
|
||||
for i=0, #cleanData-1 do
|
||||
local c = cleanData:sub(i, i)
|
||||
|
@ -191,207 +213,175 @@ local function add_pits_to_room(map)
|
|||
matrix = matrix[random(#matrix)]
|
||||
for i=2,13 do
|
||||
for j=2,10 do
|
||||
if not tile_occupied(map, (i), (j)) and matrix[i][j] then
|
||||
if matrix[i][j] then
|
||||
room.decor[i][j] = nil
|
||||
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
|
||||
add_tile(map, i, j, repack(pits.innermid))
|
||||
room.tiles[i][j] = pits.innermid
|
||||
elseif not matrix[i-1][j-1] and matrix[i-1][j] and matrix[i][j-1] then
|
||||
add_tile(map, i, j, repack(pits.innerleft))
|
||||
room.tiles[i][j] = pits.innerleft
|
||||
elseif not matrix[i+1][j-1] and matrix[i+1][j] and matrix[i][j-1] then
|
||||
add_tile(map, i, j, repack(pits.innerright))
|
||||
room.tiles[i][j] = pits.innerright
|
||||
elseif not matrix[i-1][j] and not matrix[i][j-1] and not matrix[i+1][j] then
|
||||
add_tile(map, i, j, repack(pits.topcrevice))
|
||||
room.tiles[i][j] = pits.topcrevice
|
||||
elseif not matrix[i-1][j] and not matrix[i+1][j] then
|
||||
add_tile(map, i, j, repack(pits.bottomcrevice))
|
||||
room.tiles[i][j] = pits.bottomcrevice
|
||||
elseif not matrix[i-1][j] and not matrix[i][j-1] then
|
||||
add_tile(map, i, j, repack(pits.topleft))
|
||||
room.tiles[i][j] = pits.topleft
|
||||
elseif not matrix[i+1][j] and not matrix[i][j-1] then
|
||||
add_tile(map, i, j, repack(pits.topright))
|
||||
room.tiles[i][j] = pits.topright
|
||||
elseif not matrix[i-1][j] then
|
||||
add_tile(map, i, j, repack(pits.left))
|
||||
room.tiles[i][j] = pits.left
|
||||
elseif not matrix[i+1][j] then
|
||||
add_tile(map, i, j, repack(pits.right))
|
||||
room.tiles[i][j] = pits.right
|
||||
elseif not matrix[i][j-1] then
|
||||
add_tile(map, i, j, repack(pits.top))
|
||||
room.tiles[i][j] = pits.top
|
||||
else
|
||||
add_tile(map, i, j, repack(pits.center))
|
||||
room.tiles[i][j] = pits.center
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function add_tiles_to_room (map)
|
||||
local function add_tiles_to_room (room)
|
||||
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
|
||||
add_tile(map, i, j, repack(floor.topleft))
|
||||
room.tiles[i][j] = floor.topleft
|
||||
elseif (i == 14 and j == 1) then
|
||||
add_tile(map, i, j, repack(floor.topright))
|
||||
room.tiles[i][j] = floor.topright
|
||||
elseif (i == 1 and j == 10) then
|
||||
add_tile(map, i, j, repack(floor.bottomleft))
|
||||
room.tiles[i][j] = floor.bottomleft
|
||||
elseif (i == 14 and j == 10) then
|
||||
add_tile(map, i, j, repack(floor.bottomright))
|
||||
room.tiles[i][j] = floor.bottomright
|
||||
elseif (i == 1) then
|
||||
add_tile(map, i, j, repack(floor.left))
|
||||
room.tiles[i][j] = floor.left
|
||||
elseif (i == 14) then
|
||||
add_tile(map, i, j, repack(floor.right))
|
||||
room.tiles[i][j] = floor.right
|
||||
elseif (j == 1) then
|
||||
add_tile(map, i, j, repack(floor.top))
|
||||
room.tiles[i][j] = floor.top
|
||||
elseif (j == 10) then
|
||||
add_tile(map, i, j, repack(floor.bottom))
|
||||
room.tiles[i][j] = floor.bottom
|
||||
else
|
||||
add_tile(map, i, j, repack(floor.center))
|
||||
room.tiles[i][j] = floor.center
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
add_random_decor_to_room(map)
|
||||
add_pits_to_room(map)
|
||||
end
|
||||
|
||||
local function add_walls_to_room (map)
|
||||
local function add_walls_to_room (room)
|
||||
for i=0,15 do
|
||||
for j=0,11 do
|
||||
if (i == 0 and j == 0) then
|
||||
add_tile(map, i, j, repack(wall.topleft))
|
||||
room.tiles[i][j] = wall.topleft
|
||||
elseif (i == 15 and j == 0) then
|
||||
add_tile(map, i, j, repack(wall.topright))
|
||||
room.tiles[i][j] = wall.topright
|
||||
elseif (i == 0 and j == 11) then
|
||||
add_tile(map, i, j, repack(wall.bottomleft))
|
||||
room.tiles[i][j] = wall.bottomleft
|
||||
elseif (i == 15 and j == 11) then
|
||||
add_tile(map, i, j, repack(wall.bottomright))
|
||||
room.tiles[i][j] = wall.bottomright
|
||||
elseif (i == 0 or i == 15) then
|
||||
add_tile(map, i, j, repack(wall.vertical))
|
||||
room.tiles[i][j] = wall.vertical
|
||||
elseif (j == 0 or j == 11) then
|
||||
add_tile(map, i, j, repack(wall.horizontal))
|
||||
room.tiles[i][j] = wall.horizontal
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if random(2) == 1 then
|
||||
check_add_decoration(map, 4, 3, lightDecor.candle2)
|
||||
end
|
||||
if random(2) == 1 then
|
||||
check_add_decoration(map, 11, 3, lightDecor.candle2)
|
||||
end
|
||||
if random(2) == 1 then
|
||||
check_add_decoration(map, 4, 9, lightDecor.candle2)
|
||||
end
|
||||
if random(2) == 1 then
|
||||
check_add_decoration(map, 11, 9, lightDecor.candle2)
|
||||
end
|
||||
end
|
||||
|
||||
local function add_exit(map, direction)
|
||||
if direction > 4 then return end
|
||||
|
||||
if direction == UP then
|
||||
add_tile(map, 6, 0, repack(wall.bottomright))
|
||||
add_tile(map, 7, 0, repack(floor.singleleft))
|
||||
add_tile(map, 8, 0, repack(floor.singleright))
|
||||
add_tile(map, 9, 0, repack(wall.bottomleft))
|
||||
elseif direction == LEFT then
|
||||
add_tile(map, 0, 4, repack(wall.bottomright))
|
||||
add_tile(map, 0, 5, repack(floor.singletop))
|
||||
add_tile(map, 0, 6, repack(floor.singlebottom))
|
||||
add_tile(map, 0, 7, repack(wall.topright))
|
||||
elseif direction == RIGHT then
|
||||
add_tile(map, 15, 4, repack(wall.bottomleft))
|
||||
add_tile(map, 15, 5, repack(floor.singletop))
|
||||
add_tile(map, 15, 6, repack(floor.singlebottom))
|
||||
add_tile(map, 15, 7, repack(wall.topleft))
|
||||
elseif direction == DOWN then
|
||||
add_tile(map, 6, 11, repack(wall.topright))
|
||||
add_tile(map, 7, 11, repack(floor.singleleft))
|
||||
add_tile(map, 8, 11, repack(floor.singleright))
|
||||
add_tile(map, 9, 11, repack(wall.topleft))
|
||||
end
|
||||
end
|
||||
|
||||
local function add_level_exit(map)
|
||||
success = false
|
||||
while not success do
|
||||
x = random(14)
|
||||
y = random(10)
|
||||
success = check_add_tile(map, x, y, special.level_exit)
|
||||
end
|
||||
end
|
||||
|
||||
local function build_vert_center_coridoor(map, offset)
|
||||
for j=0,4 do
|
||||
add_tile(map, 6, offset+j, repack(wall.vertical));
|
||||
add_tile(map, 7, offset+j, repack(floor.center));
|
||||
add_tile(map, 8, offset+j, repack(floor.center));
|
||||
add_tile(map, 9, offset+j, repack(wall.vertical));
|
||||
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
|
||||
end
|
||||
if random(2) == 1 then
|
||||
add_decoration(map, 6, offset + 2, repack(lightDecor.candle1))
|
||||
room.decor[6][offset+2] = lightDecor.candle1
|
||||
end
|
||||
if random(2) == 1 then
|
||||
add_decoration(map, 9, offset + 2, repack(lightDecor.candle1))
|
||||
room.decor[6][offset+2] = lightDecor.candle1
|
||||
end
|
||||
end
|
||||
|
||||
local function build_horiz_center_coridoor(map, offset)
|
||||
local function build_horiz_center_coridoor(room, offset)
|
||||
info("Building horizontal corrdior: " .. offset)
|
||||
for i=0,6 do
|
||||
add_tile(map, offset+i, 4, repack(wall.horizontal));
|
||||
add_tile(map, offset+i, 5, repack(floor.center));
|
||||
add_tile(map, offset+i, 6, repack(floor.center));
|
||||
add_tile(map, offset+i, 7, repack(wall.horizontal));
|
||||
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
|
||||
end
|
||||
if random(2) == 1 then
|
||||
check_add_decoration(map, offset+3, 4, lightDecor.candle1)
|
||||
room.decor[offset+3][4] = lightDecor.candle1
|
||||
end
|
||||
if random(2) == 1 then
|
||||
check_add_decoration(map, offset+3, 7, lightDecor.candle1)
|
||||
room.decor[offset+3][7] = lightDecor.candle1
|
||||
end
|
||||
end
|
||||
|
||||
local function build_center_corner_walls(map, exits)
|
||||
local function build_center_corner_walls(room, exits)
|
||||
if exits.down then
|
||||
if exits.left then
|
||||
add_tile(map, 6, 7, repack(wall.topright))
|
||||
room.tiles[6][7] = wall.topright
|
||||
end
|
||||
if exits.right then
|
||||
add_tile(map, 9, 7, repack(wall.topleft))
|
||||
room.tiles[9][7] = wall.topleft
|
||||
end
|
||||
else
|
||||
if not exits.left then
|
||||
add_tile(map, 6, 7, repack(wall.bottomleft))
|
||||
room.tiles[6][7] = wall.bottomleft
|
||||
end
|
||||
if not exits.right then
|
||||
add_tile(map, 9, 7, repack(wall.bottomright))
|
||||
room.tiles[9][7] = wall.bottomright
|
||||
end
|
||||
end
|
||||
if exits.up then
|
||||
if exits.left then
|
||||
add_tile(map, 6, 4, repack(wall.bottomright))
|
||||
room.tiles[6][4] = wall.bottomright
|
||||
end
|
||||
if exits.right then
|
||||
add_tile(map, 9, 4, repack(wall.bottomleft))
|
||||
room.tiles[9][4] = wall.bottomleft
|
||||
end
|
||||
else
|
||||
if not exits.left then
|
||||
add_tile(map, 6, 4, repack(wall.topleft))
|
||||
room.tiles[6][4] = wall.topleft
|
||||
end
|
||||
if not exits.right then
|
||||
add_tile(map, 9, 4, repack(wall.topright))
|
||||
room.tiles[9][4] = wall.topright
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local module = {}
|
||||
|
||||
function module.add_full_lighting(map)
|
||||
check_add_decoration(map, 4, 3, lightDecor.candle2)
|
||||
check_add_decoration(map, 11, 3, lightDecor.candle2)
|
||||
check_add_decoration(map, 4, 9, lightDecor.candle2)
|
||||
check_add_decoration(map, 11, 9, lightDecor.candle2)
|
||||
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
|
||||
end
|
||||
|
||||
function module.build_coridoor_room(map, room)
|
||||
local function build_coridoor_room(room)
|
||||
local exits = {
|
||||
up = false,
|
||||
down = false,
|
||||
|
@ -408,51 +398,126 @@ function module.build_coridoor_room(map, room)
|
|||
end
|
||||
|
||||
-- Fill the center
|
||||
add_tile(map, 6, 5, repack(wall.vertical))
|
||||
add_tile(map, 6, 6, repack(wall.vertical))
|
||||
add_tile(map, 7, 4, repack(wall.horizontal))
|
||||
add_tile(map, 7, 5, repack(floor.center))
|
||||
add_tile(map, 7, 6, repack(floor.center))
|
||||
add_tile(map, 7, 7, repack(wall.horizontal))
|
||||
add_tile(map, 8, 4, repack(wall.horizontal))
|
||||
add_tile(map, 8, 5, repack(floor.center))
|
||||
add_tile(map, 8, 6, repack(floor.center))
|
||||
add_tile(map, 8, 7, repack(wall.horizontal))
|
||||
add_tile(map, 9, 5, repack(wall.vertical))
|
||||
add_tile(map, 9, 6, repack(wall.vertical))
|
||||
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
|
||||
|
||||
-- Build the coridoors
|
||||
if exits.down then build_vert_center_coridoor(map, 7) end
|
||||
if exits.up then build_vert_center_coridoor(map, 0) end
|
||||
if exits.left then build_horiz_center_coridoor(map, 0) end
|
||||
if exits.right then build_horiz_center_coridoor(map, 9) end
|
||||
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
|
||||
|
||||
build_center_corner_walls(map, exits)
|
||||
build_center_corner_walls(room, exits)
|
||||
end
|
||||
|
||||
function module.create_room ()
|
||||
return {
|
||||
exits = {},
|
||||
active = false,
|
||||
goal = false,
|
||||
path_dir = 0,
|
||||
type = "room"
|
||||
}
|
||||
end
|
||||
|
||||
function module.build_square_room(map, room)
|
||||
add_tiles_to_room(map);
|
||||
add_walls_to_room(map);
|
||||
for exit=1, #room.exits do
|
||||
add_exit(map, room.exits[exit]);
|
||||
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(map);
|
||||
add_level_exit(room)
|
||||
end
|
||||
|
||||
if CURRENT_LEVEL > 3 and random(10) == 1 then
|
||||
directions = { "LEFT", "RIGHT", "UP", "DOWN" }
|
||||
set_modifier(map, "WINDY", directions[random(#directions)]);
|
||||
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 = {
|
||||
exits = {},
|
||||
active = false,
|
||||
goal = false,
|
||||
path_dir = 0,
|
||||
type = "room",
|
||||
tiles = {},
|
||||
decor = {},
|
||||
modifier = {
|
||||
type = nil,
|
||||
arg = nil
|
||||
},
|
||||
monsters = {}
|
||||
}
|
||||
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
|
||||
end
|
||||
|
||||
function module.build_room(room)
|
||||
if room.type == "coridoor" then
|
||||
build_coridoor_room(room)
|
||||
else
|
||||
build_normal_room(room)
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,9 +4,11 @@ local monster_gen = require "monstergen"
|
|||
map = create_map(CURRENT_LEVEL) -- 'map' needs to be global
|
||||
|
||||
room_builder.load_textures(map)
|
||||
local room = room_builder.create_room()
|
||||
|
||||
set_current_room(map, 0, 0)
|
||||
room_builder.build_square_room(map, room)
|
||||
monster_gen.add_monster_to_room(map, 0, 0);
|
||||
room_builder.add_full_lighting(map);
|
||||
local room = room_builder.create_empty_room()
|
||||
room_builder.build_room(room)
|
||||
room_builder.add_full_lighting(room)
|
||||
monster_gen.add_monsters_to_room(room, 0, 0)
|
||||
room_builder.load_room(map, room)
|
||||
monster_gen.load_monsters(map, room.monsters)
|
||||
|
|
|
@ -264,15 +264,42 @@ if random(100) == 1 then
|
|||
enemies = concat(enemies, platino);
|
||||
end
|
||||
|
||||
function module.add_monster_to_room(map, roomx, roomy)
|
||||
function module.add_monsters_to_room(room, roomx, roomy)
|
||||
local count = random(3)
|
||||
if (CURRENT_LEVEL > 3) then
|
||||
count = random(4)
|
||||
end
|
||||
for i=0,count do
|
||||
local x = (roomx * 512) + (random(13) + 1) * 32
|
||||
local y = (roomy * 384) + (random(9) + 1) * 32
|
||||
add_monster(map, x, y, repack(enemies[random(#enemies)]));
|
||||
local i = 0
|
||||
while i < count do
|
||||
local rx = random(13) + 1
|
||||
local ry = random(9) + 1
|
||||
if not room.decor[rx][ry]
|
||||
and not room.monsters[rx][ry]
|
||||
and (room.tiles[rx][ry]
|
||||
and not room.tiles[rx][ry][5]
|
||||
and not room.tiles[rx][ry][8])
|
||||
then
|
||||
|
||||
local x = (roomx * 512) + rx * 32
|
||||
local y = (roomy * 384) + ry * 32
|
||||
room.monsters[rx][ry] = {
|
||||
x,
|
||||
y,
|
||||
enemies[random(#enemies)]
|
||||
}
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function module.load_monsters(map, monsters)
|
||||
for i=0,15 do
|
||||
for j=0,11 do
|
||||
monster = monsters[i][j]
|
||||
if monster then
|
||||
add_monster(map, monster[1], monster[2], repack(monster[3]))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue