summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-10-26 12:52:34 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-10-26 12:52:34 +0200
commit57f20a5ef761985b34817846d471a064b180e089 (patch)
tree9d0029868b9e170bf07ffab9e0386b06b4189837 /main.py
downloadSnakePuzzle-57f20a5ef761985b34817846d471a064b180e089.tar.gz
SnakePuzzle-57f20a5ef761985b34817846d471a064b180e089.zip
feat: implemented simple snake game
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100755
index 0000000..52063f7
--- /dev/null
+++ b/main.py
@@ -0,0 +1,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()