All entities spawning
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -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()
|
|
||||||
.for_each(|ei| match ei.identifier.as_str() {
|
|
||||||
"Player" => {
|
|
||||||
let pos = IVec2 {
|
let pos = IVec2 {
|
||||||
x: ei.position.x * 16,
|
x: ei.position.x * 16,
|
||||||
y: 256 - ei.position.y * 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 => {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user