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!("Total layer depth: {lyr_dep}");
println!("Loading entities..."); println!("Loading entities...");
let mut player = Player::default(); // spawn all entities
// try to find the player spawn in an entities layer
lvl.layer_instances.iter().for_each(|li| { lvl.layer_instances.iter().for_each(|li| {
if li.entities.is_empty() { if li.entities.is_empty() {
return; return;
} }
li.entities li.entities.iter().for_each(|ei| {
.iter() let pos = IVec2 {
.for_each(|ei| match ei.identifier.as_str() { x: ei.position.x * 16,
y: 256 - ei.position.y * 16,
};
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" => { "Player" => {
let pos = IVec2 { spawned_ent.insert(Player { pos });
x: ei.position.x * 16, spawned_ent.insert(Sprite::from_color(Color::WHITE, vec2(16., 16.)));
y: 256 - ei.position.y * 16,
};
player = Player { pos };
} }
unk => { 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); next_state.set(AppState::Main);
} }