summaryrefslogtreecommitdiff
path: root/GameView.py
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-11-03 00:43:42 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-11-03 00:43:42 +0200
commitef6abc27cec35e32acef66c5077ffcc6bedde983 (patch)
tree62a867394c9b5af5eeff4873e12f776f2ef6b41c /GameView.py
parent1475dd4020ec24df8b29f5d90d89843b64f93f95 (diff)
downloadSnakePuzzle-ef6abc27cec35e32acef66c5077ffcc6bedde983.tar.gz
SnakePuzzle-ef6abc27cec35e32acef66c5077ffcc6bedde983.zip
feat: move on keydown alternative, som tutorial levels
Diffstat (limited to 'GameView.py')
-rw-r--r--GameView.py34
1 files changed, 22 insertions, 12 deletions
diff --git a/GameView.py b/GameView.py
index d2badfe..10fba7b 100644
--- a/GameView.py
+++ b/GameView.py
@@ -10,7 +10,8 @@ import pygame
class GameView:
- def __init__(self):
+ def __init__(self, timeBased = False):
+ self.timeBased = timeBased
self.game = Game([
"""#####O#####
@@ -36,12 +37,24 @@ class GameView:
# #
# #
#####I#####""",
-
+
"""#####D#####
# + #
# + #
# + #
# + #
+# + #
+# b _ #
+# #
+# #
+# #
+#####I#####""",
+
+"""#####D#####
+# #+# #
+# #+# #
+# #+# #
+# #+# #
# b _ #
# #
# #
@@ -130,16 +143,13 @@ class GameView:
def update(self, time):
- if self.nextControlDirection != None:
+ if self.timeBased and ((self._previousTick == None) or (self._previousTick + self._tickTime <= time)):
+ self._previousTick = time
+ if self.nextControlDirection != None:
+ self.game.snake.heading = self.nextControlDirection
+ self.nextControlDirection = None
+ self.game.tick()
+ elif (not self.timeBased) and self.nextControlDirection != None:
self.game.snake.heading = self.nextControlDirection
self.nextControlDirection = None
self.game.tick()
-
- # Time-dependent:
- # if (self._previousTick == None) or (self._previousTick + self._tickTime <= time):
- # self._previousTick = time
- # if self.nextControlDirection != None:
- # self.game.snake.heading = self.nextControlDirection
- # self.nextControlDirection = None
- # self.game.tick()
-