我目前正在Python上制作一个简单的轻飘飘的鸟类游戏。由于某种原因,当管道和鸟接触时,碰撞代码不起作用。
def collision():
global distanceDown, distanceUp
distanceUp = math.sqrt(math.pow(pipeUpX - birdX, 2) + math.pow(pipeUpY - birdY, 2)) # distance formula
distanceDown = math.sqrt(math.pow(pipeDownX - birdX, 2) + math.pow(pipeDownX - birdY, 2))
if distanceUp <= 20 or distanceDown <= 20:
return True
else:
return False
我已经在主游戏循环中调用了该函数,并要求python结束游戏(如果为真),但鸟只是通过管道。仅供参考,我没有使用OOP和类。以下是值。
pipeWidth = 50
pipeHeight = 130
pipeUpX = 800
pipeUpY = 0
pipeDownY = screenY - pipeHeight
pipeDownX = 900
pipeX_change = 1
另外,我对python和编程作为一个整体非常陌生,所以请用易于理解的代码回答。谢谢你:)
德玛西亚99
相关分类