From 4abac9a933534fb87e6ff59930533aa551c1f692 Mon Sep 17 00:00:00 2001 From: JP Stringham Date: Sat, 7 Feb 2026 14:05:52 -0500 Subject: [PATCH] All entities spawning --- src/main.rs | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1af223f..33ae851 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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() { + li.entities.iter().for_each(|ei| { + let pos = IVec2 { + 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" => { - let pos = IVec2 { - x: ei.position.x * 16, - y: 256 - ei.position.y * 16, - }; - player = Player { pos }; + 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); }