summaryrefslogtreecommitdiff
path: root/Walls.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 /Walls.py
parent394959f11cdf5493673d60df4cb7a98683fc6afc (diff)
downloadSnakePuzzle-314be3895ece7dbeb47bcdd85a05acbc4bc0ff9c.tar.gz
SnakePuzzle-314be3895ece7dbeb47bcdd85a05acbc4bc0ff9c.zip
feat: (a bit hacky) pressure plate, signal and door system
Diffstat (limited to 'Walls.py')
-rw-r--r--Walls.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Walls.py b/Walls.py
new file mode 100644
index 0000000..860a7ef
--- /dev/null
+++ b/Walls.py
@@ -0,0 +1,38 @@
+
+from Vec import Vec2
+
+
+class Walls:
+ """Contains the walls of a game.
+ Supports iterating over the walls and checking if there is a wall at a specific coordinate.
+ Useful as a wrapper to later increase performance of these operations."""
+
+ _walls = []
+
+ def __init__(self, walls):
+ self._walls = walls
+
+ def fromString(wallString):
+ walls = []
+ y = 0
+ for line in wallString.split('\n'):
+ x = 0
+ for char in line:
+ if char == "#":
+ walls.append(Vec2(x, y))
+ x += 1
+ y += 1
+ return Walls(walls)
+
+ def walls(self):
+ return self._walls
+
+ def wallAt(self, pos):
+ return (pos in self._walls)
+
+ def width(self):
+ return max(self._walls, key=lambda p: p.x).x + 1
+
+ def height(self):
+ return max(self._walls, key=lambda p: p.y).y + 1
+