All entities spawning

This commit is contained in:
JP Stringham
2026-02-07 14:05:52 -05:00
parent 8227f52259
commit 4abac9a933

View File

@@ -131,36 +131,34 @@ fn levelload(
println!("Total layer depth: {lyr_dep}");
println!("Loading entities...");
let mut player = Player::default();
// try to find the player spawn in an entities layer
// spawn all entities
lvl.layer_instances.iter().for_each(|li| {
if li.entities.is_empty() {
return;
}
li.entities
.iter()
.for_each(|ei| match ei.identifier.as_str() {
"Player" => {
li.entities.iter().for_each(|ei| {
let pos = IVec2 {
x: ei.position.x * 16,
y: 256 - ei.position.y * 16,
};
player = Player { pos };
let mut spawned_ent = commands.spawn((
Name::from(ei.identifier.clone()),
Transform::from_xyz(pos.x as f32, pos.y as f32, 100.),
));
match ei.identifier.as_str() {
"Player" => {
spawned_ent.insert(Player { pos });
spawned_ent.insert(Sprite::from_color(Color::WHITE, vec2(16., 16.)));
}
unk => {
warn!("Unhandled entity type {unk}")
spawned_ent.insert(Sprite::from_color(Color::srgb(1., 0., 1.), vec2(16., 16.)));
warn!("Unhandled entity type {unk} spawned at {pos}");
}
}
});
});
commands.spawn((
Sprite::from_color(Color::WHITE, vec2(16., 16.)),
player,
Transform::from_xyz(128., 0., 20.),
));
next_state.set(AppState::Main);
}