diff options
| -rw-r--r-- | Game.py | 6 | ||||
| -rw-r--r-- | GameView.py | 34 | ||||
| -rw-r--r-- | PressurePlate.py | 2 |
3 files changed, 25 insertions, 17 deletions
@@ -109,13 +109,13 @@ class Game: return (pos in self.snake.cells) or (pos in map(lambda box: box.pos, self.boxes)) def tick(self): - lastSnakeCell = self.snake.cells[len(self.snake.cells) - 1] + self.snake.move() + + lastSnakeCell = self.snake.cells[0]#[len(self.snake.cells) - 1] if (lastSnakeCell.x < 0 or lastSnakeCell.x >= self.width()) or (lastSnakeCell.y < 0 or lastSnakeCell.y >= self.height()): self.nextLevel() return - self.snake.move() - for static in self.statics: match static: case PressurePlate(): 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() - diff --git a/PressurePlate.py b/PressurePlate.py index fcebe4b..acc0d42 100644 --- a/PressurePlate.py +++ b/PressurePlate.py @@ -5,12 +5,10 @@ class PressurePlate: def __init__(self, pos): self.pos = pos self._trails = [] - print(f"at pos {self.pos.toString()} trails: {self._trails}") self._isActive = False def addTrail(self, trail): - print(f"plate at {self.pos.toString()} got trail: {trail}") self._trails.append(trail) |
