0
我是Love2D和Lua的新手,但到目前爲止一切進展順利。我試圖做一個簡單的遊戲,但到目前爲止,除了讓玩家不滾動屏幕之外,我一直無法找到任何碰撞。我一直試圖使用這個我不知道如何獲得基本的碰撞工作
function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2)
return x1 < x2+w2 and
x2 < x1+w1 and
y1 < y2+h2 and
y2 < y1+h1
end
但我不完全確定如何使用它,因爲每次我在程序更改時什麼都沒有嘗試。請幫忙?
我對這個網站不太熟悉,對不起。我改變了它,但它仍然不起作用。
tree = {x = 20, y = 20, speed = 0, img = nil }
tree.img = love.graphics.newImage("assets/tree.png")
function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2)
return x1 < x2+w2 or
x2 < x1+w1 or
y1 < y2+h2 or
y2 < y1+h1
end
function tree_update(dt)
if CheckCollision(crs.x, crs.y, crs.img:getWidth(), crs.img:getHeight(), tree.x, tree.y, tree.img:getWidth(), tree.img:getHeight()) then
love.graphics.print("It touched the thing", love.graphics:getWidth()/2- 50, love.graphics:getHeight()/2-10)
end
end
function tree_draw()
love.graphics.draw(tree.img, tree.x, tree.y)
end