placement collision for my tower defense
I'm currently working on a tower defense game, and am trying to check collision of all placed towers. I have a drag and Drop system that's just a list that moves all objects in the list, then remove the object when clicked, and pushes them into a "placed" list. I need to be able to check whether the dragging object is colliding with placed objects so it cant be placed there. i've used collision(x,y,width,height,x2,y2,width2,height), but it only doesn't let me place on the most recent placed towers and not all. is there any way for me to do so?
Code for reference:
initDrag = function() dragging = [] full = 0 full2 = 0 placed = [] end
updateDrag = function() for d in dragging d.x = mouse.x d.y = mouse.y if mouse.pressed then if collision(-75,70,11,60,d.x,d.y,d.width,d.width) or collision(0,45,160,10,d.x,d.y,d.width,d.width) or collision(50,85,60,10,d.x,d.y,d.width,d.width) or collision(75,65,10,50,d.x,d.y,d.width,d.width) or collision(25,40,10,100,d.x,d.y,d.width,d.width) or collision(-5,-5,70,10,d.x,d.y,d.width,d.width) or collision(-35,-25,10,50,d.x,d.y,d.width,d.width) or collision(-55,-45,50,10,d.x,d.y,d.width,d.width) or collision(-75,-60,10,40,d.x,d.y,d.width,d.width) or collision(-15,-75,130,10,d.x,d.y,d.width,d.width) or collision(45,-55,10,50,d.x,d.y,d.width,d.width) or collision(70,-35,60,10,d.x,d.y,d.width,d.width) then full = 1 else full = 0 end if full == 0 then for p in placed end end end end end
drawDrag = function() for d in dragging screen.drawRect(d.x,d.y,d.width,d.width,"red") end end
drop = function(d) dragging.removeElement(d) end