So I'm trying to make a procedural dungeon generator, but the problem is my number generator keeps generating new numbers and there for it keeps moving tiles. Is there anyway I can just make numbers that it generates static? I've tried storing them in a table then accessing the table but that didn't work. The code is posted below.
function dungeongen()
grass = love.graphics.newImage("data/tile0.png")
stone = love.graphics.newImage("data/tile2.png")
math.randomseed(love.timer.getTime())
cell = {}
for y=0, 32 do
for x=0,32 do
cell[x] = {love.graphics.draw(grass, x*32, y*32)}
end
end
for i=0, 16 do
local x = math.random(1, 64 )
local y = math.random(1, 64 )
love.graphics.draw(stone, x*32, y*32)
end
end
You need to understand that everything (except love.load) is in a loop. So if you call dungeongen() in love.draw, that code is going to be run several times per second. That means that you're reloading those images several times per second, and those random values are also reset several times per second.
The way to do it would be to generate a table in love load, containing all those values (a map, if you will). Then you can iterate over that table in love.draw when you want to draw it.
Yeah, but the way I'm doing it currently isn't working when I'm trying to draw more tiles to make a room. Take a look and tell me what I'm doing wrong cause clearly this isn't working the way it's intended.
function dungeongen()
floor= {}
for i=1, 26 do
x = Randomnumber[i]
y = Randomnumber[i+1]
for p=1, x/16 do
for p2=1, y/16 do
floor[i] = love.graphics.draw(stonetile, x*32, y*32)
end
end
end
end
Nevermind, Fixed it wrong algorithm. It was suppose to be (x*32)+(p*32), once again, silly me.