问题描述
我正在尝试做到这一点,所以当我的红色圆圈碰到白色圆圈时,它就无法越过它。 我已经尝试过基本的if语句,但是它不起作用。无论如何,这里是代码...
win = love.window.setMode(600,600)
Xpos = 300
TX = 50
function love.draw()
love.graphics.setColor(1,1,1)
love.graphics.circle("fill",Xpos,200,25)
love.graphics.setColor(1,0)
love.graphics.circle("fill",TX,60)
if Xpos == TX then
Xpos = Xpos + 0.1
end
if TX >= Xpos then
TX = TX - 35
end
if love.keyboard.isDown("right") then
TX = TX + 5
end
end
解决方法
尝试使用基本的AABB碰撞检测器:
function Something:collides(target)
if self.x > target.x + target.width or target.x > self.x + self.width then
return false
end
if self.y > target.y + target.height or target.y > self.y + self.height then
return false
end
end