needing help with collision and detecting if collision has hit "displayMask"
Posted: Sun May 14, 2023 10:05 am
first forum post
im making a pizza tower fangame, pizza tower has these masks for detecting if something has hit a wall. im trying to add this into LOVE2D via a CheckCollision function, but it doesnt seem to work.
heres my code
it display as a out ot bounds pixel, and im not even sure if i did the collision direction detection right. can someone help?
im making a pizza tower fangame, pizza tower has these masks for detecting if something has hit a wall. im trying to add this into LOVE2D via a CheckCollision function, but it doesnt seem to work.
heres my code
Code: Select all
function Player:CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2)
local ct = {left = false, right = false, up = false, down = false}
local col_x,col_y = nil,nil
if x1 < x2+w2 and
x2 < x1+w1 and
y1 < y2+h2 and
y2 < y1+h1 then
if x1 < x2 then
ct.left = true
col_x = x2
elseif x1 > x2 then
ct.right = true
col_x = x2+w2
end if y1 > y2+(h2/2) then
ct.down = true
col_y = y2
elseif y2+(h2/2) > y1 then
ct.up = true
col_y = y2+h2
end
if self.displayMask:getPixel(x1 - col_x, y1 - col_y) then
return ct
else
return false
end
end
return false
end