-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfood.py
42 lines (34 loc) · 1.27 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
import numpy as np
from p5 import *
from settings import Settings
class Food:
def __init__(self, settings):
self.settings: Settings = settings
self.spawnLocations = []
self.spawnIndex = 0
self.x = 15 * self.settings.scale
self.y = 15 * self.settings.scale
self.eaten = False
self.isFoodForBestSnake = False
self.spawnLocations = self.settings.spawnLocations
def update(self):
if(self.eaten == False):
self.show()
else:
self.spawnAtRandomLocation()
def spawnAtRandomLocation(self):
self.x = self.spawnLocations[self.spawnIndex][0]
self.y = self.spawnLocations[self.spawnIndex][1]
# self.x = np.random.randint(self.settings.gridUnits) * self.settings.scale
# self.y = np.random.randint(self.settings.gridUnits) * self.settings.scale
self.spawnIndex += 1
self.eaten = False
def spawnAtInitialLocation(self):
self.x = self.spawnLocations[self.spawnIndex][0]
self.y = self.spawnLocations[self.spawnIndex][1]
self.spawnIndex += 1
self.eaten = False
def show(self):
# if(self.isFoodForBestSnake):
fill(100, 0, 100)
square((self.x, self.y), self.settings.scale)