vehicles protect from damage now, though not perfectly

This commit is contained in:
yuni 2024-04-05 03:52:46 +02:00
parent df9f47c427
commit e577a5084c

View file

@ -310,16 +310,22 @@ pub fn handle_vehicle_enter_exit(
fn handle_collisions(
mut collision_event_reader: EventReader<CollisionStarted>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
q_player: Query<Entity, With<PlayerCamera>>,
q_player: Query<(Entity, Option<&Player>), With<PlayerCamera>>,
mut q_player_lifeform: Query<(&mut LifeForm, &mut Suit, &mut HitPoints), With<Player>>,
) {
if let (Ok(player), Ok((mut lifeform, mut suit, mut hp))) = (q_player.get_single(), q_player_lifeform.get_single_mut()) {
if let (Ok((player, player_maybe)), Ok((mut lifeform, mut suit, mut hp))) = (q_player.get_single(), q_player_lifeform.get_single_mut()) {
for CollisionStarted(entity1, entity2) in collision_event_reader.read() {
if *entity1 == player || *entity2 == player {
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Crash));
lifeform.adrenaline_jolt += 0.1;
suit.integrity -= 0.03;
hp.damage += 10.0;
if player_maybe.is_some() {
suit.integrity -= 0.03;
hp.damage += 10.0;
}
else {
hp.damage += 3.0;
}
}
}
}