-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (33 loc) · 873 Bytes
/
Copy pathmain.py
File metadata and controls
43 lines (33 loc) · 873 Bytes
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
import pygame
from src.game import SnakeGame
def main():
FPS = 5
GUI = True
pygame.init()
snake = SnakeGame()
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
direction = None
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
direction = 'left'
if keys[pygame.K_RIGHT]:
direction = 'right'
if keys[pygame.K_UP]:
direction = 'up'
if keys[pygame.K_DOWN]:
direction = 'down'
snake.move(direction)
if GUI:
snake.draw()
pygame.display.flip()
if snake.ended:
running = False
clock.tick(FPS)
pygame.quit()
if __name__ == '__main__':
main()