Skip to content

Commit

Permalink
food
Browse files Browse the repository at this point in the history
  • Loading branch information
femto committed Aug 17, 2023
1 parent b48e9df commit 4567036
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions snake_game_py/food.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from snake_game_py.snake import Point # Import Point from snake.py to avoid redundancy

class Food:

def __init__(self, snake_segments):
self.position = Point(0, 0)
self.snake_segments = snake_segments
self.generate()

def generate(self):
"""Generate food at a random position on the screen, ensuring it's not on the snake."""
Expand All @@ -16,12 +19,9 @@ def generate(self):
if potential_position not in self.snake_segments:
self.position = potential_position
break
def __init__(self, snake_segments):
self.position = Point(0, 0)
self.snake_segments = snake_segments
self.generate()

def draw(self, screen):
"""Draw the food on the screen."""
pygame.draw.rect(screen, (255, 0, 0),
pygame.draw.rect(screen, (255, 0, 0),
#this is it
(self.position.x * BLOCK_SIZE, self.position.y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE))

0 comments on commit 4567036

Please sign in to comment.