#!/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()