#!/usr/bin/env python3 """Generates maps/level1.tmx (Tiled-compatible) for the test platformer level. Tile legend: G = grass top (GID 1, green box) # = dirt (GID 2, brown box) S = stone (GID 3, grey box) """ import os W, H = 64, 32 grid = [["."] * W for _ in range(H)] def fill(x0, y0, x1, y1, ch): for y in range(y0, y1 + 1): for x in range(x0, x1 + 1): grid[y][x] = ch # Ground: rows 29-31, with two gaps (cols 18-21 and 44-47) fill(0, 29, 17, 31, "#") grid[29][0:18] = ["G"] * 18 fill(22, 29, 43, 31, "#") grid[29][22:44] = ["G"] * 22 fill(48, 29, 63, 31, "#") grid[29][48:64] = ["G"] * 16 # Small dirt step near spawn fill(3, 27, 4, 28, "#") # Stone platform ladder (each step <= 3 tiles up, gaps of ~2 tiles) fill(6, 25, 10, 25, "S") # P1 fill(13, 22, 17, 22, "S") # P2 fill(20, 19, 24, 19, "S") # P3 (high left) fill(26, 25, 30, 25, "S") # P4 fill(33, 22, 37, 22, "S") # P5 fill(40, 19, 44, 19, "S") # P6 (high right) fill(47, 16, 51, 16, "S") # P7 (topmost) LEGEND = {"G": 1, "#": 2, "S": 3, ".": 0} rows_csv = [] for row in grid: rows_csv.append(",".join(str(LEGEND[c]) for c in row)) csv_data = "\n ".join(rows_csv) tmx = f''' {csv_data} ''' out = os.path.join(os.path.dirname(__file__), "..", "maps", "level1.tmx") with open(out, "w") as f: f.write(tmx) print(f"wrote {os.path.abspath(out)} ({W}x{H})")