Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance for Food's random position initialization #4

Open
douglascdev opened this issue Sep 2, 2020 · 0 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@douglascdev
Copy link
Owner

douglascdev commented Sep 2, 2020

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()]
)
  • Change the way the second argument is passed to this function, passing the group and checking for collisions with it instead, to improve performance.
  • Keep the full list of points on screen in memory for the function and only limit the width and height within the generator.
  • If the excluded_rects is empty, return a random item of the list without creating the rects_without_collision list.
@douglascdev douglascdev added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant