Here is my mousepressed function:
Code: Select all
function love.mousepressed(x, y, button)
placeWallBP(x, y) -- draw walls
if button == 2 then -- if you right clicked
wallIs, wallWhich = checkWallBP(x, y) -- check if there is a wall BP in the grid section you clicked
if wallIs == 1 then -- if there is a wall, remove that wall from the arry
table.remove(wallbpX, wallWhich)
table.remove(wallbpY, wallWhich)
end
end
end
Code: Select all
function checkWallBP(x, y)
for i = 1, #wallbpX do -- check through each wall in the table for how many walls there are
if coordtoGrid(wallbpX[i]) == coordtoGrid(x) and coordtoGrid(wallbpY[i]) == coordtoGrid(y) then -- if there is a wall on the X spot and a wall on the Y spot, return true and where the wall is in the array
return 1, i
end
end
return 0
end
Walls are drawn like this:
Code: Select all
function drawWallBP()
for i = 1, #wallbpX do
love.graphics.draw(wallbpImg, wallbpX[i], wallbpY[i])
end
end
any ideas folks?