Code: Select all
map =
{
walls =
{
wall1 =
{
id = 1, x = 100, y = 605, w = 190, h = 35, block = "up"
},
wall2 =
{
id = 2, x = 300 - 40, y = 640-200, w = 35, h = 195, block = "left"
},
wall3 =
{
id = 3, x = 100, y = 735, w = 300, h = 35, block = "down"
},
wall4 =
{
id = 4, x = 65, y = 605, w = 35, h = 165, block = "left"
},
wall5 =
{
id = 5, x = 400, y = 440, w= 35, h = 330, block = "right"
}
}
}
function drawWalls(x, y, w, h)
love.graphics.setColor(50, 50, 200, 255)
love.graphics.rectangle("fill", x, y, w, h)
end
function updateWalls()
local i,v
for i,v in pairs(map.walls) do
local px,py = player:getPos()
local pxo, pyo = player:getOffset()
local x, y, w, h, block = v.x, v.y, v.w, v.h, v.block
local col = checkCollision(px-pxo, py-pyo, player.width, player.height, x, y, w, h)
if col == true then
if block == "left" and player.canwalk.left == true then
player.canwalk.left = false
elseif block == "up" then
player.canwalk.up = false
elseif block == "down" then
player.canwalk.down = false
elseif block == "right" then
player.canwalk.right = false
end
end
if col == false then
if block ~= "left" and player.canwalk.left == false then
player.canwalk.left = true
end
if block == "right" then
player.canwalk.right = true
end
if block == "up" then
player.canwalk.up = true
end
if block == "down" then
player.canwalk.down = true
end
end
end
end