summaryrefslogtreecommitdiff
path: root/main.py
blob: 52063f739b1855a5f029c311fe3929cb93dc7184 (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
#!/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:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    keys = pygame.key.get_pressed()
    if keys[pygame.K_w] and view.game.snake.heading != Vec.up.neg():
        view.nextControlDirection = Vec.up
    elif keys[pygame.K_a] and view.game.snake.heading != Vec.left.neg():
        view.nextControlDirection = Vec.left
    elif keys[pygame.K_r] and view.game.snake.heading != Vec.down.neg():
        view.nextControlDirection = Vec.down
    elif keys[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()