-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33f337c
commit f07121b
Showing
6 changed files
with
59 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
pub mod damage; | ||
pub mod death; | ||
pub mod hit; | ||
// TODO: pub mod knockback | ||
pub mod knockback; | ||
|
||
use bevy::prelude::*; | ||
|
||
pub(super) fn plugin(app: &mut App) { | ||
app.add_plugins((hit::plugin, damage::plugin, death::plugin)); | ||
app.add_plugins(( | ||
damage::plugin, | ||
death::plugin, | ||
hit::plugin, | ||
knockback::plugin, | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use avian2d::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
use crate::game::combat::hit::OnHit; | ||
use crate::util::prelude::*; | ||
|
||
pub(super) fn plugin(app: &mut App) { | ||
app.configure::<HitboxKnockback>(); | ||
} | ||
|
||
#[derive(Component, Reflect)] | ||
#[reflect(Component)] | ||
pub struct HitboxKnockback { | ||
pub force: f32, | ||
} | ||
|
||
impl Configure for HitboxKnockback { | ||
fn configure(app: &mut App) { | ||
app.register_type::<Self>(); | ||
app.observe(apply_hitbox_knockback); | ||
} | ||
} | ||
|
||
fn apply_hitbox_knockback( | ||
trigger: Trigger<OnHit>, | ||
hitbox_query: Query<(&GlobalTransform, &HitboxKnockback)>, | ||
mut hurtbox_query: Query<(&GlobalTransform, &mut LinearVelocity)>, | ||
) { | ||
let &OnHit(hitbox, hurtbox) = trigger.event(); | ||
let (hitbox_gt, knockback) = r!(hitbox_query.get(hitbox)); | ||
let (hurtbox_gt, mut velocity) = r!(hurtbox_query.get_mut(hurtbox)); | ||
|
||
let hitbox_pos = hitbox_gt.translation().xy(); | ||
let hurtbox_pos = hurtbox_gt.translation().xy(); | ||
let direction = Dir2::new(hurtbox_pos - hitbox_pos).unwrap_or(Dir2::EAST); | ||
velocity.0 += knockback.force * direction; | ||
} |