douglascdev / snake

A snake game made with Python3 and Pygame!
https://www.pygame.org/project/5080
Apache License 2.0
4 stars 5 forks source link

Improve performance for Food's random position initialization #4

Open douglascdev opened 4 years ago

douglascdev commented 4 years ago

When a Food object is created, a random generation function is used to create it's position, excluding the snake's position from the possible generated positions:

self.rect = random_pos_rect(
    Game.DEFAULT_RECT, [sprite.rect for sprite in snake_group.sprites()]
)