From: Simon Cross Date: Sat, 10 Sep 2016 20:49:00 +0000 (+0200) Subject: Add tunnel generator. X-Git-Tag: tabakrolletjie-v1.0.0~42 X-Git-Url: https://git.ctpug.org.za/?p=tabakrolletjie.git;a=commitdiff_plain;h=e4293bddb43d45dd56ef54c798ebc55076c3d97a;ds=sidebyside Add tunnel generator. --- 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)