change y again, add StateScoped to level and player, optimize level sel.
This commit is contained in:
parent
dffaadf7ec
commit
56dd566af8
2 changed files with 25 additions and 8 deletions
|
@ -88,12 +88,15 @@ fn pan_camera(
|
|||
}
|
||||
|
||||
fn translate_grid_coords_entities(
|
||||
mut grid_coords_entities: Query<(&mut Transform, &GridCoords), Changed<GridCoords>>,
|
||||
mut grid_coords_entities: Query<
|
||||
(&mut Transform, &GridCoords),
|
||||
(With<Player>, Changed<GridCoords>),
|
||||
>,
|
||||
pan: Res<PanLevel>,
|
||||
) {
|
||||
// TODO: what is this used for? Why it doesn't work for a moving Player?
|
||||
for (mut transform, grid_coords) in grid_coords_entities.iter_mut() {
|
||||
// info!("translated pan offset: {}", pan.offset);
|
||||
info!("Changed GridCoords: {grid_coords:?}");
|
||||
transform.translation = (bevy_ecs_ldtk::utils::grid_coords_to_translation(
|
||||
*grid_coords,
|
||||
IVec2::splat(GRID_SIZE),
|
||||
|
@ -117,6 +120,7 @@ pub enum Direction {
|
|||
E,
|
||||
S,
|
||||
W,
|
||||
// we ignore the diagonals NE SE NW SW
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for Direction {
|
||||
|
@ -218,6 +222,7 @@ pub fn spawn_level(
|
|||
|
||||
commands.spawn((
|
||||
Name::new("Ldtk level"),
|
||||
StateScoped(Screen::Gameplay),
|
||||
LdtkWorldBundle {
|
||||
ldtk_handle: level_assets.world.clone(),
|
||||
transform: Transform::from_xyz(-half_size.x, half_size.y, 0.0),
|
||||
|
@ -374,6 +379,11 @@ fn level_selection_follow_player(
|
|||
};
|
||||
|
||||
if level_bounds.contains(player_transform.translation().truncate()) {
|
||||
if *level_selection == LevelSelection::Iid(level_iid.clone()) {
|
||||
// Player is already in the current level, no need to change
|
||||
return Ok(());
|
||||
}
|
||||
info!("Setting current level to {level_iid}");
|
||||
*level_selection = LevelSelection::Iid(level_iid.clone());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue