here's how I create my map and draw it
Code: Select all
function love.load()
map = {}
map.width = 10
map.height = 10
for x = 0, map.width do
map[x] = {}
for y = 0, map.height do
if y < 5 then
map[x][y] = 1
elseif y == 5 then
map[x][y] = 3
elseif y == 5+1 then
map[x][y] = 3
elseif y == 5+2 then
map[x][y] = math.random(2,3)
else
map[x][y] = 2
end
end
end
end
function love.draw()
love.graphics.setColor(255,255,255,255)
for x = 0, map.width do
for y = 0, map.height do
if map[x][y] == 3 then
love.graphics.rectangle("line",x*32,y*32,32,32)
elseif map[x][y] == 2 then
love.graphics.rectangle("fill",x*32,y*32,32,32)
end
end
end
end
function mapCollide(x, y)
local checkMap = map[math.floor(x/32)][math.floor(y/32)]
return checkMap
end
function love.update(dt)
local mapX = math.floor(love.mouse.getX()/32)
local mapY = math.floor(love.mouse.getY()/32)
if love.mouse.isDown(1) and mapCollide(love.mouse.getX(), love.mouse.getY()) == 1 then
map[mapX][mapY] = 2
end
if love.mouse.isDown(2) and mapCollide(love.mouse.getX(), love.mouse.getY()) < 5 then
map[mapX][mapY] = 1
end
end
Please help