-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (38 loc) · 1.32 KB
/
main.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 pyxel
from Class.Snake import Snake
from Class.Fruit import Fruit
class App:
def __init__(self):
pyxel.init(128, 128, title="Jeu")
pyxel.load("snake.pyxres")
self.snake = Snake([64, 64], [0, -8], True)
self.snake.grow()
self.fruit = Fruit()
self.dir_change = False
pyxel.run(self.update, self.draw)
def update(self):
if pyxel.frame_count % 15 == 0:
self.snake.move()
self.dir_change = False
if self.snake.on_wall() or self.snake.on_tail(self.snake.pos):
quit_app()
if not self.dir_change:
if pyxel.btnp(pyxel.KEY_RIGHT):
self.snake.change_direction([-self.snake.direction[1], self.snake.direction[0]])
self.dir_change = True
elif pyxel.btnp(pyxel.KEY_LEFT):
self.snake.change_direction([self.snake.direction[1], -self.snake.direction[0]])
self.dir_change = True
if self.snake.pos == self.fruit.pos:
self.snake.grow()
self.fruit.pos = None
if self.fruit.pos is None:
self.fruit.spawn(self.snake)
def draw(self):
pyxel.cls(0)
pyxel.bltm(0, 0, 0, 0, 0, 128, 128)
self.snake.draw()
self.fruit.draw()
def quit_app():
pyxel.quit()
App()