this repo has no description

ghost marker component

+13 -9
+13 -9
src/ghost.rs
··· 13 13 app.add_systems(Startup, setup); 14 14 } 15 15 16 + #[derive(Component)] 17 + pub struct Ghost; 18 + 16 19 pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { 17 20 commands.spawn(Camera2d); 18 21 let mut rng = rand::rng(); ··· 25 28 for _ in 1..100 { 26 29 commands.spawn(( 27 30 Plan::new(), 31 + Ghost, 28 32 BerriesEaten(0), 29 33 Name::new(fake::faker::name::raw::FirstName(EN).fake::<String>()), 30 34 Sprite::from_image(asset_server.load("ghost.png")), ··· 53 57 fn find_closest_berry( 54 58 In(input): In<OperatorInput>, 55 59 mut commands: Commands, 56 - berries: Query<(Entity, &Transform), (With<Berry>, Without<TargetedBerry>, Without<Plan>)>, 57 - planner: Query<&Transform, With<Plan>>, 60 + berries: Query<(Entity, &Transform), (With<Berry>, Without<TargetedBerry>)>, 61 + ghosts: Query<&Transform, With<Ghost>>, 58 62 ) -> OperatorStatus { 59 - let pos = planner.get(input.entity).unwrap().translation.xy(); 63 + let pos = ghosts.get(input.entity).unwrap().translation.xy(); 60 64 let mut closest: Option<Entity> = None; 61 65 let mut closest_dist = 0.0; 62 66 for (entity, transform) in berries { ··· 76 80 77 81 fn go_to_berry( 78 82 In(input): In<OperatorInput>, 79 - mut planners: Query<(&mut Transform, &TargetBerry, &BerriesEaten), With<Plan>>, 80 - berries: Query<&Transform, (With<Berry>, Without<Plan>)>, 81 - new_berries: Query<&Transform, (With<Berry>, Without<TargetedBerry>, Without<Plan>)>, 83 + mut ghosts: Query<(&mut Transform, &TargetBerry, &BerriesEaten), With<Ghost>>, 84 + berries: Query<&Transform, (With<Berry>, Without<Ghost>)>, 85 + new_berries: Query<&Transform, (With<Berry>, Without<TargetedBerry>, Without<Ghost>)>, 82 86 time: Res<Time>, 83 87 mut news: MessageReader<NewBerry>, 84 88 mut commands: Commands, 85 89 ) -> OperatorStatus { 86 - let Ok((mut trans, target_entity, eaten)) = planners.get_mut(input.entity) else { 90 + let Ok((mut trans, target_entity, eaten)) = ghosts.get_mut(input.entity) else { 87 91 return OperatorStatus::Failure; 88 92 }; 89 93 ··· 123 127 124 128 fn collect_berry( 125 129 In(input): In<OperatorInput>, 126 - mut planners: Query<(&TargetBerry, &mut BerriesEaten), With<Plan>>, 130 + mut ghosts: Query<(&TargetBerry, &mut BerriesEaten), With<Ghost>>, 127 131 mut commands: Commands, 128 132 ) -> OperatorStatus { 129 - let Ok((berry, mut eaten)) = planners.get_mut(input.entity) else { 133 + let Ok((berry, mut eaten)) = ghosts.get_mut(input.entity) else { 130 134 return OperatorStatus::Failure; 131 135 }; 132 136 eaten.0 += 1;