I am trying to make a game using Python (with turtle) the aim of the game is to shoot the other person
The problem comes with the collision code. I am checking collisions with bullets using dist()
, but that seems to cause the loop to exit/freeze (I don't really know which).
I've tried using distance formula instead of the function but that didn't change anything
Here is my code:
bullet.forward(10)
distancetop1 = dist(player1.pos(),bullet.pos())
if self != player1 and distancetop1 < 2:
bullet.clear()
print("orange won!")
exit()
distancetop2 = dist(player1.pos(),bullet.pos())
if self != player2 and distancetop2 < 2:
bullet.clear()
print("blue won!")
exit()
My full code, if needed, is here
With turtle don't put your key checks in a loop. Set them once then call
listen
. Usemainloop
to keep the game running.Try this code: