All entities spawning
This commit is contained in:
36
src/main.rs
36
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user