Compare commits

..

No commits in common. "2b8e04e4d69b987efe3e07da7c5b54ba4c43ce49" and "f35f7abce735ad5c8ee7e47bf6f964a7b94b4e90" have entirely different histories.

2 changed files with 2 additions and 49 deletions

View file

@ -32,14 +32,9 @@ impl Plugin for GamePlugin {
SystemSet::on_update(AppState::Game)
.with_system(crate::levels::post_setup_level)
.with_system(keyboard_input_system)
.with_system(character_particle_effect_system)
.with_system(move_camera),
)
.add_system_set(
SystemSet::on_update(AppState::Win)
.with_system(keyboard_input_system)
.with_system(move_camera),
.with_system(character_particle_effect_system),
)
.add_system_set(SystemSet::on_update(AppState::Win).with_system(keyboard_input_system))
.add_system_to_stage(CoreStage::PostUpdate, collision_event_system);
}
}
@ -93,14 +88,12 @@ fn setup(
mut commands: Commands,
mut current_level: ResMut<CurrentLevel>,
mut level_startup_event: EventWriter<LevelStartupEvent>,
mut camera_query: Query<&mut Transform, With<Camera>>,
) {
let level_id = LevelId(current_level.0.map_or(0, |level_id| level_id.0 + 1));
crate::levels::setup_level(
&mut commands,
&mut current_level,
&mut level_startup_event,
&mut camera_query,
level_id,
);
}
@ -303,40 +296,3 @@ fn win_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
})
.insert(Level);
}
fn move_camera(
mut camera_query: Query<(&Camera, &mut Transform, &GlobalTransform)>,
characters: Query<(&CharacterId, &Transform), Without<Camera>>,
level_query: Query<&SelectedCharacterId>,
) {
const MARGIN: f32 = 128.0;
if let Ok(selected_character_id) = level_query.get_single() {
if let Some(selected_character_id) = &selected_character_id.0 {
if let Some((_character_id, transform)) = characters
.iter()
.find(|(character_id, _transform)| *character_id == selected_character_id)
{
let (camera, mut camera_transform, camera_global_transform) =
camera_query.single_mut();
let pos = camera
.world_to_viewport(camera_global_transform, transform.translation)
.unwrap();
let size = camera.logical_viewport_size().unwrap();
if pos.x < MARGIN {
camera_transform.translation.x += pos.x - MARGIN;
}
if pos.x > size.x - MARGIN {
camera_transform.translation.x += MARGIN + pos.x - size.x;
}
if pos.y < MARGIN {
camera_transform.translation.y += pos.y - MARGIN;
}
if pos.y > size.y - MARGIN {
camera_transform.translation.y += MARGIN + pos.y - size.y;
}
}
}
}
}

View file

@ -13,7 +13,6 @@ pub fn setup_level(
commands: &mut Commands,
current_level: &mut ResMut<CurrentLevel>,
level_startup_event: &mut EventWriter<LevelStartupEvent>,
camera_query: &mut Query<&mut Transform, With<Camera>>,
level_id: LevelId,
) {
let level_entity = commands
@ -24,8 +23,6 @@ pub fn setup_level(
.id();
current_level.0 = Some(level_id);
camera_query.single_mut().translation = Default::default();
level_startup_event.send(LevelStartupEvent(level_entity));
}