From e4293bddb43d45dd56ef54c798ebc55076c3d97a Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 10 Sep 2016 22:49:00 +0200 Subject: [PATCH] Add tunnel generator. --- misc/tunnels.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 misc/tunnels.py diff --git a/misc/tunnels.py b/misc/tunnels.py new file mode 100644 index 0000000..b93a8b9 --- /dev/null +++ b/misc/tunnels.py @@ -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) -- 2.34.1