Skip to content

Commit

Permalink
primary enemy follows player
Browse files Browse the repository at this point in the history
  • Loading branch information
sim82 committed Nov 25, 2023
1 parent ecbc072 commit 66b5ab8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/droid/ai.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::player::PlayerMarker;
use crate::weapon::PROJECTILE_SPEED;
use crate::{droid::WeaponState, weapon::Projectile};
use bevy::{
Expand Down Expand Up @@ -90,6 +91,18 @@ pub struct EnemyEvaluation {
direction: Vec2,
}

fn enemy_select_system(
mut query: Query<&mut PrimaryEnemy>,

player_query: Query<Entity, With<PlayerMarker>>,
) {
let Some(enemy) = player_query.iter().next() else {
return;
};
for mut primary_enemy in &mut query {
primary_enemy.enemy = enemy;
}
}
fn enemy_evaluation_system(
mut query: Query<(&mut EnemyEvaluation, &PrimaryEnemy, &Transform)>,
droid_query: Query<&Transform>,
Expand Down Expand Up @@ -327,6 +340,7 @@ impl Plugin for AiPlugin {
// .with_system(incomping_projectile_evaluation_system),
// );

app.add_systems(PreUpdate, enemy_select_system);
app.add_systems(
Update,
(
Expand Down
12 changes: 8 additions & 4 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct PlayerMarker;
fn enter_droid(
mut commands: Commands,
query: Query<(Entity, &Transform), With<DroidMarker>>,
ship_query: Query<&Transform, (With<PlayerMarker>, With<ShipMarker>)>,
ship_query: Query<&Transform, /*(With<PlayerMarker>,*/ With<ShipMarker>>,
) {
let Ok(ship_transform) = ship_query.get_single() else {
return;
Expand Down Expand Up @@ -76,12 +76,13 @@ fn exit_droid(
#[allow(clippy::type_complexity)]
fn enter_ship(
mut commands: Commands,
query: Query<Entity, (With<PlayerMarker>, With<ShipMarker>)>,
query: Query<Entity, /*(With<PlayerMarker>, */ With<ShipMarker>>,
) {
for entity in &query {
commands
.entity(entity)
.insert(PrimaryPlayerBundle::default());
.insert(PrimaryPlayerBundle::default())
.insert(PlayerMarker);
}
}

Expand All @@ -94,7 +95,10 @@ fn exit_ship(
>,
) {
for (entity, mut ship_input) in &mut query {
commands.entity(entity).remove::<PrimaryPlayerBundle>();
commands
.entity(entity)
.remove::<PrimaryPlayerBundle>()
.remove::<PlayerMarker>();
*ship_input = ShipInput::default();
}
}
Expand Down

0 comments on commit 66b5ab8

Please sign in to comment.