Add tunnel generator.
authorSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 20:49:00 +0000 (22:49 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 20:49:00 +0000 (22:49 +0200)
misc/tunnels.py [new file with mode: 0644]

diff --git a/misc/tunnels.py b/misc/tunnels.py
new file mode 100644 (file)
index 0000000..b93a8b9
--- /dev/null
@@ -0,0 +1,46 @@
+""" Generate some tunnels and print them. """
+
+import json
+import sys
+
+replace = None
+if len(sys.argv) == 2:
+    replace = sys.argv[1]
+
+obstacle_defaults = {
+    "type": "wall",
+    "vertices": [],
+}
+
+w, h = 1024, 704
+cx, cy = int(w / 2), int(h / 2)
+gap_width = 88
+wall_width = 64
+block_width = gap_width + wall_width
+
+
+def make_wall(i, j):
+    wall = obstacle_defaults.copy()
+    top = cx - (gap_width / 2) + (i * block_width)
+    bottom = top - wall_width
+    left = cy + (gap_width / 2) + (j * block_width)
+    right = left + wall_width
+    wall["vertices"] = [
+        [left, top], [right, top], [right, bottom], [left, bottom],
+    ]
+    return wall
+
+walls = []
+
+for i in (-2, -1, 0, 1):
+    for j in (-2, -1, 0, 1, 2, 3):
+        walls.append(make_wall(i, j))
+
+if replace:
+    with open(replace, "r") as f:
+        station = json.load(f)
+    station["obstacles"] = walls
+    with open(replace, "w") as f:
+        json.dump(station, f, indent=2)
+else:
+    print json.dumps(walls, indent=2)