Code: Select all
function createDungeon()
--start generating rooms
local roomWidth = 1
local roomHeight = 1
local roomX = 1
local roomY = 1
for roomCount=1, roomsToCreate do
local badRoom = true
repeat
--pick some random x,y coordinates on the map and also randomly determine the size of our room
--rooms of the same size are boring
roomWidth = love.math.random(minRoomWidth, maxRoomWidth)
roomHeight = love.math.random(minRoomHeight, maxRoomHeight)
roomX = love.math.random(1, dungeonWidth - roomWidth)
roomY = love.math.random(1, dungeonHeight - roomHeight)
--badRoom = CheckRoomPlacement(roomX, roomY, roomWidth, roomHeight)
--love.window.showMessageBox("Overlap check complete", tostring(doRoomsOverlap), "error")
badRoom = CheckRoomPlacement(roomX, roomY, roomWidth, roomHeight)
until badRoom == false
--now let's set that position in our table to be a 1 (tile)
dungeonRooms[roomCount] = {roomX, roomY, roomWidth, roomHeight}
for xPos=roomX, roomX + roomWidth do
for yPos=roomY, roomY + roomHeight do
dungeon[yPos][xPos] = 1
end -- end for
end -- end for
end -- end for loop
end
Code: Select all
function CheckRoomPlacement(x, y, width, height)
local badPlacement = false
--if we try to place a 1 where there is already a 1, then we are overlapping our rooms
for xPos=x, x + width do
for yPos=y, y + height do
if dungeon[y][x] == 1 then
love.window.showMessageBox("True", "Bad room placement found", "error")
return true
end
end
end
return false
end