Player spawn point

This commit is contained in:
2024-02-28 13:14:48 -08:00
parent d6db2f3e5f
commit d084e4dba3
7 changed files with 179 additions and 5 deletions

View File

@ -12,10 +12,20 @@ sys_map map_{{map_name}} = {
.width={{width}},
.height={{height}},
};
{% for entity_type in entity_types %}
void map_{{map_name}}_{{entity_type}}_create(sys_i32 x, sys_i32 y);
{% endfor %}
void map_{{map_name}}_create_entities() {
{% for entity in entities %}
map_{{map_name}}_{{entity.type}}_create({{entity.x}}, {{entity.y}});
{% endfor %}
}
""".lstrip()
def main(map_name, fname_ldtk, fname_c):
width, height, tiles = load_mapdata(fname_ldtk)
width, height, tiles, entities = load_mapdata(fname_ldtk)
with open(fname_c, "wt") as output:
output.write(
@ -24,6 +34,8 @@ def main(map_name, fname_ldtk, fname_c):
tiles=tiles,
width=width,
height=height,
entity_types=sorted(set(i["type"] for i in entities)),
entities=entities,
)
)
@ -49,7 +61,12 @@ def load_mapdata(fname_ldtk):
if layer["__identifier"] == "entities":
for e in layer["entityInstances"]:
raise NotImplementedError()
# TODO: Other fields?
entities.append({
"type": e["__identifier"],
"x": e["__worldX"] // 8,
"y": e["__worldY"] // 8,
})
x_min = 0
y_min = 0
@ -66,7 +83,7 @@ def load_mapdata(fname_ldtk):
else:
dense_tiles.append(255)
return width, height, dense_tiles
return width, height, dense_tiles, entities
def annot_xy(lst, w, h):