To stop player movement, I theorized that by checking if the coordinates of where the player wanted to move are inside that of a wall, then it disables movement.
Code: Select all
function entCollidePoint(ent,cx,cy) --entity table name, point we're checking's x position, point we're checking's y position
for i,v in ipairs(ent) do
local xcheck, ycheck
if cx>v.x and cx<v.x+v.w then
xcheck=true
else
xcheck=false
end
if cy>v.y and cy<v.y+v.h then
ycheck=true
else
ycheck=false
end
return xcheck and ycheck
end
Code: Select all
if love.keyboard.isDown('up')==true then
vk_up=1
else
vk_up=0
end
if love.keyboard.isDown('down')==true then
vk_down=1
else
vk_down=0
end
if love.keyboard.isDown('left')==true then
vk_left=1
else
vk_left=0
end
if love.keyboard.isDown('right')==true then
vk_right=1
else
vk_right=0
end
--PLAYER CODE
for i,v in ipairs(player) do
if entCollidePoint(box,v.x+4,v.y)==false and entCollidePoint(box,v.x-4,v.y)==false then
v.x=v.x+((vk_right-vk_left)*4)
end
if entCollidePoint(box,v.x,v.y+4)==false and entCollidePoint(box,v.x,v.y-4)==false then
v.y=v.y+((vk_down-vk_up)*4)
end
end