Here's the code:
Code: Select all
function love.update(dt)
if CheckCollision(player.x, player.y, player.w, player.h, blockx, blocky, blockw, blockh) then
blockcollision = true
end
if love.keyboard.isDown("a") then
if blockcollision == false then
textx = textx + player.spd * dt
blockx = blockx + player.spd * dt
end
elseif love.keyboard.isDown("d") then
if blockcollision == false then
textx = textx - player.spd * dt
blockx = blockx - player.spd * dt
end
end
if love.keyboard.isDown("w") then
if blockcollision == false then
texty = texty + player.spd * dt
blocky = blocky + player.spd * dt
end
elseif love.keyboard.isDown("s") then
if blockcollision == false then
texty = texty - player.spd * dt
blocky = blocky - player.spd * dt
end
end
end
function CheckCollision(x1, y1, w1, h1, x2, y2, w2, h2)
return x1 < x2 + w2 and
x2 < x1 + w1 and
y1 < y2 + h2 and
y2 < y1 + h1
end