test tiles

This commit is contained in:
2025-06-16 20:46:03 -05:00
parent ba6ecf9006
commit c9f795e55c
10 changed files with 188 additions and 84 deletions

View File

@ -365,8 +365,11 @@ for chunkY in range(mapHeightInRealChunks):
f.write(f" .entities = {{\n")
for entity in entities:
# Entities are center aligned in tiled.
localX = entity['x'] - (topLeftTileX * TILE_WIDTH)
localY = entity['y'] - (topLeftTileY * TILE_HEIGHT)
localX = round(entity['x'] - (topLeftTileX * TILE_WIDTH))
localY = round(entity['y'] - (topLeftTileY * TILE_HEIGHT))
if 'type' in entity and entity['type'] not in ENTITY_TYPE_MAP:
continue
f.write(" {\n")
f.write(f" .id = {entity['id']},\n")
@ -379,6 +382,20 @@ for chunkY in range(mapHeightInRealChunks):
f.write("};\n\n")
# Determine map global things
playerSpawnX = 0
playerSpawnY = 0
for ob in objectLayer['objects']:
if 'type' not in ob or ob['type'] != 'player_spawn':
continue
if 'x' not in ob or 'y' not in ob:
print(f"Error: Player spawn object does not contain 'x' or 'y' key.")
sys.exit(1)
playerSpawnX = round(ob['x'])
playerSpawnY = round(ob['y'])
break
# Output header file.
headerPath = os.path.join(worldDir, "world.h")
with open(headerPath, 'w') as f:
@ -404,5 +421,7 @@ with open(headerPath, 'w') as f:
f.write("NULL, ")
f.write("\n")
f.write("};\n\n")
f.write(f"#define WORLD_PLAYER_SPAWN_X {playerSpawnX}\n")
f.write(f"#define WORLD_PLAYER_SPAWN_Y {playerSpawnY}\n")
print(f"chunks.h generated at: {headerPath}")