Skip to content

Commit

Permalink
Despawns player arrows when they hit walls
Browse files Browse the repository at this point in the history
  • Loading branch information
mnmaita committed Dec 21, 2024
1 parent 6ac0cc8 commit 0873df1
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion game/src/game/attack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ pub mod particles;

use std::mem;

use arc_attack::Arrow;
use rapier2d::prelude::InteractionGroups;
use theseeker_engine::gent::Gent;
use theseeker_engine::physics::{
update_sprite_colliders, Collider, PhysicsWorld, GROUND,
update_sprite_colliders, Collider, PhysicsWorld, GROUND, PLAYER_ATTACK,
};

use super::enemy::{Defense, EnemyGfx, EnemyStateSet, JustGotHitMarker};
Expand Down Expand Up @@ -60,6 +62,7 @@ impl Plugin for AttackPlugin {
// cleanup
attack_tick,
despawn_projectile,
despawn_player_arrows,
attack_cleanup,
)
.chain()
Expand Down Expand Up @@ -417,6 +420,32 @@ pub fn despawn_projectile(
}
}

pub fn despawn_player_arrows(
query: Query<(Entity, &Transform, &Collider), With<Arrow>>,
spatial_query: Res<PhysicsWorld>,
mut commands: Commands,
) {
for (entity, transform, collider) in query.iter() {
let is_arrow_intersecting_with_ground = !spatial_query
.intersect(
transform.translation.xy(),
collider.0.shape(),
InteractionGroups {
memberships: PLAYER_ATTACK,
filter: GROUND,
},
None,
)
.is_empty();

if is_arrow_intersecting_with_ground {
// Note: purposefully does not despawn child entities, nor remove the
// reference, so that child particle systems have the option of lingering
commands.entity(entity).despawn();
}
}
}

pub fn kill_on_damage(
query: Query<(Entity, &Health), With<Gent>>,
mut damage_events: EventReader<DamageInfo>,
Expand Down

0 comments on commit 0873df1

Please sign in to comment.