fix contact damage and test with impaler

This commit is contained in:
Jim 2025-08-26 08:26:59 -04:00
parent 9d397451c4
commit e9790f156d
Signed by: jim
GPG key ID: 3236D2F059A7C0AC
6 changed files with 16 additions and 13 deletions

1
Cargo.lock generated
View file

@ -1644,6 +1644,7 @@ dependencies = [
"bevy", "bevy",
"building", "building",
"combat", "combat",
"combat_damagers",
"state", "state",
] ]

View file

@ -13,12 +13,12 @@
MouseMovementY: [ MouseMovementY: [
CameraPanY, CameraPanY,
], ],
KeyCode(Escape): [
TogglePause,
],
MouseButton(Middle): [ MouseButton(Middle): [
CameraOrbitEnable, CameraOrbitEnable,
], ],
KeyCode(Escape): [
TogglePause,
],
KeyCode(F1): [ KeyCode(F1): [
ToggleDebugUI, ToggleDebugUI,
], ],

View file

@ -10,6 +10,7 @@ avian3d = { workspace = true }
state = { path = "../state" } state = { path = "../state" }
combat = { path = "../combat" } combat = { path = "../combat" }
building = { path = "../building" } building = { path = "../building" }
combat_damagers = { path = "../combat_damagers" }
[lints] [lints]
workspace = true workspace = true

View file

@ -6,6 +6,7 @@ use avian3d::prelude::*;
use bevy::prelude::*; use bevy::prelude::*;
use building::Building; use building::Building;
use combat::{Defense, Health}; use combat::{Defense, Health};
use combat_damagers::ContactDamage;
use state::GameSystemSet; use state::GameSystemSet;
pub struct BuildingImpalerPlugin; pub struct BuildingImpalerPlugin;
@ -47,6 +48,7 @@ fn spawn(
transform.clone(), transform.clone(),
Health::new(20.0), Health::new(20.0),
Defense::new(5.0), Defense::new(5.0),
ContactDamage { amount: 5.0 },
Name::from("Impaler"), Name::from("Impaler"),
)); ));
} }

View file

@ -19,6 +19,7 @@ impl Plugin for CombatDamagersPlugin {
} }
#[derive(Component)] #[derive(Component)]
#[require(CollisionEventsEnabled)]
pub struct ContactDamage { pub struct ContactDamage {
pub amount: f32, pub amount: f32,
} }
@ -29,6 +30,7 @@ fn deal_contact_damage(
mut commands: Commands, mut commands: Commands,
) { ) {
for event in reader.read() { for event in reader.read() {
info!("event recv!");
if let Ok(contact) = query.get(event.0) { if let Ok(contact) = query.get(event.0) {
commands.trigger_targets( commands.trigger_targets(
Attacked { Attacked {

View file

@ -10,9 +10,9 @@ use bevy::{
render::camera::Exposure, render::camera::Exposure,
}; };
use building_core::SpawnCore; use building_core::SpawnCore;
use building_impaler::SpawnImpaler; use building_impaler::{Impaler, SpawnImpaler};
use camera::ControlledCamera; use camera::ControlledCamera;
use combat::{Attacked, Defense, Health}; use combat::{Defense, Health};
use state::AppState; use state::AppState;
pub struct LevelPlugin; pub struct LevelPlugin;
@ -64,16 +64,13 @@ fn setup(
)) ))
.observe( .observe(
|trigger: Trigger<Pointer<Click>>, |trigger: Trigger<Pointer<Click>>,
mut query: Query<&mut LinearVelocity>, target: Single<&GlobalTransform, With<Impaler>>,
mut commands: Commands| { mut query: Query<(&GlobalTransform, &mut LinearVelocity)>| {
if let Ok(mut v) = query.get_mut(trigger.target()) { if let Ok((gtf, mut v)) = query.get_mut(trigger.target()) {
let delta = target.translation() - gtf.translation();
v.y += 5.0; v.y += 5.0;
v.0 += delta;
} }
commands.entity(trigger.target()).trigger(Attacked {
attacker: None,
amount: 8.,
..default()
});
}, },
); );
} }