-
Notifications
You must be signed in to change notification settings - Fork 0
/
Food.py
51 lines (36 loc) · 1.09 KB
/
Food.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pygame
from random import randint
class Food:
def __init__(self):
self._X = 600
self._Y = 400
self.food = None
self.dimension = 10
# region Getters & Setters
@property
def X(self):
return self._X
@X.setter
def X(self, coordinate):
self._X = coordinate
@property
def Y(self):
return self._Y
@Y.setter
def Y(self, coordinate):
self._Y = coordinate
# endregion
def display(self, surface, color):
self.food = pygame.draw.rect(surface, color, (self.X, self.Y, self.dimension, self.dimension))
def align_on_grid(self):
self.X = self.X // 10 * 10
self.Y = self.Y // 10 * 10
def generate_food(self, boundaries):
top_boundary = boundaries[0] + 10
bottom_boundary = boundaries[1] - 10
left_boundary = boundaries[2] + 10
right_boundary = boundaries[3] - 10
self.X = randint(left_boundary, right_boundary)
self.Y = randint(top_boundary, bottom_boundary)
self.align_on_grid()
return self.X, self.Y