66 lines
1.6 KiB
Python
66 lines
1.6 KiB
Python
import random
|
|
import math
|
|
|
|
def generate_defold_map():
|
|
width = 30
|
|
height = 20
|
|
|
|
# Defold/Tileset Indices (0-based)
|
|
# 0: Grass
|
|
# 1: Water
|
|
# 2: Tall Grass
|
|
# 3: Dense Grass
|
|
|
|
cells = []
|
|
|
|
for x in range(width):
|
|
# River logic: Sine wave center
|
|
# y goes from 0 (bottom) to height (top) in Defold usually?
|
|
# Actually Defold coords: (0,0) is bottom-left usually, but in Tilemap editor (0,0) is often bottom-left too.
|
|
# Let's assume standard grid.
|
|
|
|
river_center = 10 + int(3 * math.sin(x * 0.2))
|
|
|
|
for y in range(height):
|
|
tile_id = 0 # Default Grass
|
|
|
|
# River check
|
|
if y == river_center or y == river_center + 1:
|
|
tile_id = 1 # Water
|
|
else:
|
|
# Random foliage on grass
|
|
if random.random() < 0.10:
|
|
tile_id = random.choice([2, 3])
|
|
|
|
# Append cell string
|
|
# Defold tilemap cell format
|
|
cell_str = f""" cell {{
|
|
x: {x}
|
|
y: {y}
|
|
tile: {tile_id}
|
|
h_flip: 0
|
|
v_flip: 0
|
|
}}"""
|
|
cells.append(cell_str)
|
|
|
|
# Full file content
|
|
content = f"""tile_set: "/main/ground.tilesource"
|
|
layers {{
|
|
id: "ground"
|
|
z: 0.0
|
|
is_visible: 1
|
|
{chr(10).join(cells)}
|
|
}}
|
|
material: "/builtins/materials/tile_map.material"
|
|
blend_mode: BLEND_MODE_ALPHA
|
|
"""
|
|
|
|
output_path = 'main/ground.tilemap'
|
|
with open(output_path, 'w') as f:
|
|
f.write(content)
|
|
|
|
print(f"Generated Defold tilemap at {output_path}")
|
|
|
|
if __name__ == "__main__":
|
|
generate_defold_map()
|