-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheighth_task.py
33 lines (26 loc) · 1.08 KB
/
eighth_task.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
#background render method
def image_display(self):
bg_img = pygame.image.load(" ")
self.surface.blit(bg_img, (0,0))
#play_method
def play(self):
self.image_display()
self.snake.walk()
self.food.eat()
self.display_score()
pygame.display.flip()
# snake eating food
for i in range(self.snake.length):
if self.is_collision(self.snake.x[i], self.snake.y[i], self.food.x, self.food.y):
self.play_sound(" ")
self.snake.increase_length()
self.food.random_shift()
# snake colliding with itself
for i in range(3, self.snake.length):
if self.is_collision(self.snake.x[0], self.snake.y[0], self.snake.x[i], self.snake.y[i]):
self.play_sound(' ')
raise "Snake collided with self"
# snake colliding with the boundaries of the window
if not (0 <= self.snake.x[0] <= 1000 and 0 <= self.snake.y[0] <= 800):
self.play_sound(' ')
raise "You hit the boundary"