map colisions
I've figured out how to use AABB to detect collisions with sprites but what if my sprite walks into a wall and how do I make it so it stops instead of going through it?
code for the test where I figured out how to do sprite collisions
init = function()
text = "no collision"
speed = 3
playerX = 0
playerY = 100
end
movement = function()
if keyboard.DOWN then
playerY -= speed
elsif keyboard.UP then
playerY += speed
elsif keyboard.LEFT then
playerX -= speed
elsif keyboard.RIGHT then
playerX += speed
end
end
update = function()
a_min_x = -25
a_min_y = -25
a_max_x = 25
a_max_y = 25
b_min_x = playerX - 25
b_min_y = playerY - 25
b_max_x = playerX + 25
b_max_y = playerY + 25
movement()
if a_min_x <= b_max_x and b_min_x <= a_max_x and a_min_y <= b_max_y and b_min_y <= a_max_y then
text = "collision!"
else
text = "no collision"
end
end
draw = function()
screen.clear()
screen.drawSprite("icon",0,0,50)
screen.drawSprite("sprite",playerX,playerY,50)
screen.drawText(text,150,75,20)
end