Why Collision Between Two Moving Objects On Pygame Dont Work?
I am doing a snake game(there is two snakes on the game) with pygame and i want to detect when the snake head collides with the another snake body, do that for both and a special c
Solution 1:
You need to evaluate whether the head of snake is in the list snake2, including the head of snake2:
if snake[0] in snake2:
gameOverBlue()
and if the head of snake2 is in snake:
if snake2[0] in snake:
gameOverRed()
If you want to detect if the heads of the snakes are colliding the you have to compare snake[0] and snake2[0] separately:
if snake[0] == snake2[0]:
print("heads are colliding")
if snake[0] in snake2[1:]:
gameOverBlue()
if snake2[0] in snake[1:]:
gameOverRed()
Post a Comment for "Why Collision Between Two Moving Objects On Pygame Dont Work?"