summaryrefslogtreecommitdiff
path: root/GameView.py
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-11-01 21:46:26 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-11-01 23:42:16 +0200
commit314be3895ece7dbeb47bcdd85a05acbc4bc0ff9c (patch)
tree6fb7f6a8b8c6edc5301ef3e3dad0a2c4b4435200 /GameView.py
parent394959f11cdf5493673d60df4cb7a98683fc6afc (diff)
downloadSnakePuzzle-314be3895ece7dbeb47bcdd85a05acbc4bc0ff9c.tar.gz
SnakePuzzle-314be3895ece7dbeb47bcdd85a05acbc4bc0ff9c.zip
feat: (a bit hacky) pressure plate, signal and door system
Diffstat (limited to 'GameView.py')
-rw-r--r--GameView.py49
1 files changed, 30 insertions, 19 deletions
diff --git a/GameView.py b/GameView.py
index 50785a7..3b458d8 100644
--- a/GameView.py
+++ b/GameView.py
@@ -1,6 +1,10 @@
from Game import Game
from Box import Box
+from Door import Door
+from PressurePlate import PressurePlate
+from Trail import Trail
+
import pygame
class GameView:
@@ -31,29 +35,36 @@ class GameView:
surface.fill("black")
for cell in self.game.walls.walls():
- pygame.draw.rect(surface, "white", pygame.Rect(
- cell.x*self.cellWidth,
- cell.y*self.cellWidth,
- self.cellWidth,
- self.cellWidth
- ))
+ self._drawBoxOfColor(surface, "white", cell.x, cell.y)
+
+ for static in self.game.statics:
+ match static:
+ case Door():
+ if static.isOpen():
+ self._drawBoxOfColor(surface, "lightgray", static.pos.x, static.pos.y)
+ else:
+ self._drawBoxOfColor(surface, "gray", static.pos.x, static.pos.y)
+ case PressurePlate():
+ self._drawBoxOfColor(surface, "yellow", static.pos.x, static.pos.y)
+ case Trail():
+ if static.isOn():
+ self._drawBoxOfColor(surface, "pink", static.pos.x, static.pos.y)
+ else:
+ self._drawBoxOfColor(surface, "purple", static.pos.x, static.pos.y)
for box in self.game.boxes:
- pygame.draw.rect(surface, "brown", pygame.Rect(
- box.pos.x*self.cellWidth,
- box.pos.y*self.cellWidth,
- self.cellWidth,
- self.cellWidth
- ))
+ self._drawBoxOfColor(surface, "brown", box.pos.x, box.pos.y)
for cell in self.game.snake.cells:
- pygame.draw.rect(surface, "red", pygame.Rect(
- cell.x*self.cellWidth,
- cell.y*self.cellWidth,
- self.cellWidth,
- self.cellWidth
- ))
-
+ self._drawBoxOfColor(surface, "red", cell.x, cell.y)
+
+ def _drawBoxOfColor(self, surface, color, x, y):
+ pygame.draw.rect(surface, color, pygame.Rect(
+ x*self.cellWidth,
+ y*self.cellWidth,
+ self.cellWidth,
+ self.cellWidth
+ ))
def update(self, time):