[Solved] snake game: snake colliding with itself


In your code it looks as though you are checking if the head of the snake collide with itself, which will always return True. You need to individually check that the head of snake does not collide with any of it’s trailing segments:

for segment in SnakeSegments[2:]:
    if pygame.sprite.collide_rect(h, segment):
        pass # collision detected, game-over

The head of the snake is expected to collide with the segment directly behind it, which is why we need to start with the 3rd element in the list.

1

solved snake game: snake colliding with itself