summaryrefslogtreecommitdiff
path: root/main.py
blob: 688589cc13023ad9134a393c75833523e661ca60 (plain)
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
#!/bin/python

import pygame
import Vec
from GameView import GameView


view = GameView()

nextControlDirection = None
pygame.init
screen = pygame.display.set_mode((view.width(), view.height()))
clock = pygame.time.Clock()
running = True

while running:

    match view.game.snake:
        case None: raise ValueError("no snake")
        case _:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_w and view.game.snake.heading != Vec.up.neg():
                        view.nextControlDirection = Vec.up
                    elif event.key == pygame.K_a and view.game.snake.heading != Vec.left.neg():
                        view.nextControlDirection = Vec.left
                    elif event.key == pygame.K_r and view.game.snake.heading != Vec.down.neg():
                        view.nextControlDirection = Vec.down
                    elif event.key == pygame.K_s and view.game.snake.heading != Vec.right.neg():
                        view.nextControlDirection = Vec.right

    if view.isRunning():
        view.update(pygame.time.get_ticks())

    # fill the screen with a color to wipe away anything from last frame
    screen.fill("purple")

    view.render(screen)

    pygame.display.flip()

    clock.tick(60)  # limits FPS to 60

pygame.quit()