-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_ai.py
50 lines (36 loc) · 1.29 KB
/
main_ai.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
import arcade
from snake import Snake
from apple import Apple
class Game(arcade.Window) :
def __init__(self):
super().__init__(width=512 , height=512 , title= "Super Snake 🐍🍎")
arcade.set_background_color(arcade.color.KHAKI)
self.snake = Snake(self)
self.food=Apple(self)
def on_draw(self):
arcade.start_render()
self.snake.draw()
self.food.draw()
arcade.finish_render()
def on_update(self, delta_time: float):
self.snake.move()
if self.snake.center_y > self.food.center_y :
self.snake.change_x = 0
self.snake.change_y = -1
elif self.snake.center_y < self.food.center_y :
self.snake.change_x = 0
self.snake.change_y = 1
elif self.snake.center_x > self.food.center_x :
self.snake.change_x = -1
self.snake.change_y = 0
elif self.snake.center_x < self.food.center_x :
self.snake.change_x = 1
self.snake.change_y = 0
self.snake.on_update(delta_time)
self.food.on_update()
if arcade.check_for_collision(self.snake , self.food):
self.snake.eat(self.food)
self.food = Apple(self)
if __name__ == "__main__" :
game = Game()
arcade.run()