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 seedX = love.math.random(1024)
local seedY = love.math.random(1024)
local w, h = 25*4, 19*4-1
map = {}
for y = 1, h do
map[y] = {}
for x = 1, w do
local value = love.math.noise( 0.04*x+seedX, 0.14*y+seedY)
if value > 0.7 then -- 70% air and 30% ground
map[y][x] = g -- ground
else
map[y][x] = a -- air
end
end
end
end
function love.draw()
local scale = 0.25
for y, xs in ipairs (map) do
for x, tile in ipairs (xs) do
love.graphics.draw(tile.image, (x-1)*tileSize*scale, (y-1)*tileSize*scale, 0, scale, scale)
end
end
end
tile-generation-02.png (23.6 KiB) Viewed 3047 times
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
gg = {image = love.graphics.newImage("ground-grass.png")} -- image 32x32 pixels
local seedX = love.math.random(1024)
local seedY = love.math.random(1024)
local w, h = 25, 19
map = {}
for y = 1, h do
map[y] = {}
for x = 1, w do
local value = love.math.noise( 0.04*x+seedX, 0.14*y+seedY)
if value > 0.7 then -- 70% air and 30% ground
if map[y-1] and map[y-1][x] and map[y-1][x] == a then
-- one tile above was an air
map[y][x] = gg -- ground grass
else
map[y][x] = g -- ground
end
else
map[y][x] = a -- air
end
end
end
end
function love.draw()
local scale = 1
for y, xs in ipairs (map) do
for x, tile in ipairs (xs) do
love.graphics.draw(tile.image, (x-1)*tileSize*scale, (y-1)*tileSize*scale, 0, scale, scale)
end
end
end
tile-generation-03.png (22.31 KiB) Viewed 2999 times
if value > 0.7 then -- 70% air and 30% ground
if map[y-1] and map[y-1][x] and map[y-1][x] == a then
-- one tile above was an air
map[y][x] = gg -- ground grass
else
map[y][x] = g -- ground
if value >= 0.6 and value <= 0.65 then
map[y][x] = ore
end
end
else
map[y][x] = a -- air
end
for y = 1, h do
map[y] = {}
for x = 1, w do
local value = love.math.noise( 0.04*x+seedX, 0.14*y+seedY)
if value > 0.7 then -- 70% air and 30% ground
if map[y-1] and map[y-1][x] and map[y-1][x] == a then
map[y][x] = gg -- ground with grass
elseif math.random (6) == 1 then
map[y][x] = go -- ground with ore
else
map[y][x] = g -- ground
end
else
map[y][x] = a -- air
end
end
end
tile-generation-04.png (24.61 KiB) Viewed 2791 times