Procedural Terrain Generation from Tables
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Procedural Terrain Generation from Tables
Can someone help me to code a Procedural Terrain Generation from Tables?
Re: Procedural Terrain Generation from Tables
Can you show the example of source information and how the result must looking for?
Re: Procedural Terrain Generation from Tables
So you have an empty table named terrain. There are variables g and a. a has air.png, and g has ground.png. then it will put the variables in the tables like this: terrain = {a,a,a,a
g,g,g,a
g,a,a,g
g,g,g,g} when it will generate the table it will somehow draw the terrain.
g,g,g,a
g,a,a,g
g,g,g,g} when it will generate the table it will somehow draw the terrain.
Re: Procedural Terrain Generation from Tables
Also it won't be the same terrain, it will generate not the same.
Re: Procedural Terrain Generation from Tables
The simplest way to do it is (not tested):KedyZ wrote: ↑Sun Sep 25, 2022 2:26 pm So you have an empty table named terrain. There are variables g and a. a has air.png, and g has ground.png. then it will put the variables in the tables like this: terrain = {a,a,a,a
g,g,g,a
g,a,a,g
g,g,g,g} when it will generate the table it will somehow draw the terrain.
Code: Select all
tileSize = 32 -- for image 32x32 pixels
a = {image = love.graphics.newImage("air.png")} -- image 32x32 pixels
g = {image = love.graphics.newImage("ground.png")} -- image 32x32 pixels
map = {
{a,a,a,a},
{g,g,a,g},
{g,a,a,g},
{g,g,g,g},
}
Code: Select all
function love.draw()
for y, xs in ipairs (map) do
for x, tile in ipairs (xs) do
love.graphics.draw(tile.image, (x-1)*tileSize, (y-1)*tileSize)
end
end
end
https://love2d.org/wiki/love.math.noise
Code: Select all
local w, h = 4, 4
map = {}
for y = 1, h do
map[y] = {}
for x = 1, w do
local value = love.math.noise( x*10, y*10 ) -- x10 makes more thick randomness
if value > 0.8 then -- 80% air and 20% ground
map[y][x] = g -- ground
else
map[y][x] = a -- air
end
end
end
Last edited by darkfrei on Mon Sep 26, 2022 1:31 pm, edited 1 time in total.
Re: Procedural Terrain Generation from Tables
procedual generation just shows me nothing
Re: Procedural Terrain Generation from Tables
nevermind but it shows the same every time and if i want to put it in function.load it shows me that i need to put an end at line 1
Re: Procedural Terrain Generation from Tables
Don't forget to define a and g.
Code: Select all
-- License CC0 (Creative Commons license) (c) darkfrei, 2022
function love.load()
tileSize = 32 -- for image 32x32 pixels
a = {image = love.graphics.newImage("air.png")} -- image 32x32 pixels
g = {image = love.graphics.newImage("ground.png")} -- image 32x32 pixels
local w, h = 25, 18
map = {}
for y = 1, h do
map[y] = {}
for x = 1, w do
local value = love.math.noise( 0.08*x, 0.2*y)
if value > 0.8 then -- 80% air and 20% ground
map[y][x] = g -- ground
else
map[y][x] = a -- air
end
end
end
end
function love.update(dt)
end
function love.draw()
for y, xs in ipairs (map) do
for x, tile in ipairs (xs) do
love.graphics.draw(tile.image, (x-1)*tileSize, (y-1)*tileSize)
end
end
end
Re: Procedural Terrain Generation from Tables
still the same when you open it twice
Re: Procedural Terrain Generation from Tables
do i need to put a random number generator somewhere?
Who is online
Users browsing this forum: Google [Bot] and 3 guests