Last active
February 2, 2020 12:13
-
-
Save arpit-omprakash/439ea4e1a3f3820d11ab03b5bbe2ca52 to your computer and use it in GitHub Desktop.
A class for food objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The class for food object | |
class Food(): | |
# Initialization | |
def __init__(self): | |
self.x = screen_width/2 | |
self.y = screen_height/4 | |
self.color = red | |
self.width = 10 | |
self.height = 10 | |
# Makes the food visible | |
def draw_food(self, surface): | |
self.food = pg.Rect(self.x, self.y, self.width, self.height) | |
pg.draw.rect(surface, self.color, self.food) | |
# Is the food eaten? | |
def is_eaten(self, head): | |
return self.food.colliderect(head) | |
# Returns a new position for the food after it is eaten | |
def new_pos(self): | |
self.x = random.randint(0,screen_width-self.width) | |
self.y = random.randint(0,screen_height-self.height) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment