Skip to content

Commit

Permalink
Changed immunity to component and also added card configuration for h…
Browse files Browse the repository at this point in the history
…itbox damage and immunity
  • Loading branch information
ramirezmike committed Jul 29, 2024
1 parent 2e9785c commit 5529ab5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
3 changes: 2 additions & 1 deletion assets/config/card.ron
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
action: Step,
action_modifier: CardActionModifier(
remove_on_beat: 8,
immune_during_action: true,
hitbox_damage: (15.0, 0.5),
immunity: Some(0.5),
),
),
/*"splits": Card(
Expand Down
2 changes: 1 addition & 1 deletion src/game/actor/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn player(key: impl Into<String>) -> impl EntityCommand {
FaceCursor,
// Contact hitbox was for testing, but it's funny, so I'm leaving it in.
Hitbox,
HitboxDamage(15.0),
HitboxDamage(0.0),
HitboxKnockback(5.0),
HurtSfx,
DeathSfx,
Expand Down
24 changes: 18 additions & 6 deletions src/game/card/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::game::card::attack::AimTowardsFacing;
use crate::game::card::attack::AttackOnBeat;
use crate::game::card::movement::MoveTowardsFacing;
use crate::game::cleanup::RemoveOnBeat;
use crate::game::combat::hit::Hurtbox;
use crate::game::cleanup::RemoveOnTimer;
use crate::game::combat::damage::HitboxDamage;
use crate::game::combat::hit::Immune;
use crate::util::prelude::*;

pub(super) fn plugin(app: &mut App) {
Expand Down Expand Up @@ -44,9 +46,19 @@ impl FromWorld for CardActionMap {
modifier.remove_on_beat,
));

// TODO: Remove player check if we decide immunity should apply to all
if entity.contains::<IsPlayer>() && modifier.immune_during_action {
entity.remove::<Hurtbox>();
// Player actor has extra benefits
if entity.contains::<IsPlayer>() {
entity.insert(RemoveOnTimer::bundle(
HitboxDamage(modifier.hitbox_damage.0),
Timer::from_seconds(modifier.hitbox_damage.1, TimerMode::Once),
));

if let Some(timer) = modifier.immunity {
entity.insert(RemoveOnTimer::bundle(
Immune,
Timer::from_seconds(timer, TimerMode::Once),
));
}
}
},
),
Expand Down Expand Up @@ -112,8 +124,8 @@ pub struct CardActionModifier {
/// Remove component when this timer finishes.
remove_on_timer: Timer,
attack: Attack,
// if true, actor is immune while performing this action
immune_during_action: bool,
immunity: Option<f32>,
hitbox_damage: (f32, f32), // damage, time
heal_percent: f32,
heal_flat: f32,
}
1 change: 0 additions & 1 deletion src/game/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ impl<C: Component + TypePath> Configure for RemoveOnTimer<C> {
}
}

#[allow(dead_code)]
impl<C: Component + TypePath> RemoveOnTimer<C> {
pub fn new(timer: Timer) -> Self {
Self {
Expand Down
2 changes: 2 additions & 0 deletions src/game/combat/damage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::prelude::*;

use crate::game::cleanup::RemoveOnTimer;
use crate::game::combat::hit::OnHit;
use crate::util::prelude::*;

Expand All @@ -18,6 +19,7 @@ impl Configure for HitboxDamage {
fn configure(app: &mut App) {
app.register_type::<Self>();
app.observe(apply_hitbox_damage);
app.configure::<RemoveOnTimer<Self>>();
}
}

Expand Down
32 changes: 13 additions & 19 deletions src/game/combat/hit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use bevy::prelude::*;
use bevy_kira_audio::prelude::*;

use crate::core::UpdateSet;
use crate::game::audio::music::on_full_beat;
use crate::game::cleanup::RemoveOnTimer;
use crate::screen::playing::PlayingAssets;
use crate::util::prelude::*;

pub(super) fn plugin(app: &mut App) {
app.configure::<(Hitbox, Hurtbox, OnHit, HurtSfx)>();
app.configure::<(Hitbox, Hurtbox, OnHit, HurtSfx, Immune)>();
}

#[derive(Component, Reflect)]
Expand All @@ -23,28 +23,22 @@ impl Configure for Hitbox {

#[derive(Component, Reflect)]
#[reflect(Component)]
pub struct Hurtbox;
pub struct Immune;

impl Configure for Hurtbox {
impl Configure for Immune {
fn configure(app: &mut App) {
app.register_type::<Self>();

app.add_systems(
Update,
readd_hurtbox
.in_set(UpdateSet::SyncEarly)
.run_if(on_full_beat(2)),
);
app.configure::<RemoveOnTimer<Self>>();
}
}

fn readd_hurtbox(
mut commands: Commands,
hitbox_query: Query<Entity, (With<Hitbox>, Without<Hurtbox>)>,
) {
for entity in &hitbox_query {
let mut entity = c!(commands.get_entity(entity));
entity.insert(Hurtbox);
#[derive(Component, Reflect)]
#[reflect(Component)]
pub struct Hurtbox;

impl Configure for Hurtbox {
fn configure(app: &mut App) {
app.register_type::<Self>();
}
}

Expand All @@ -62,7 +56,7 @@ fn trigger_hit(
mut commands: Commands,
mut collision_events: EventReader<CollisionStarted>,
hitbox_query: Query<(), With<Hitbox>>,
hurtbox_query: Query<(), With<Hurtbox>>,
hurtbox_query: Query<(), (With<Hurtbox>, Without<Immune>)>,
) {
for &CollisionStarted(a, b) in collision_events.read() {
for (a, b) in [(a, b), (b, a)] {
Expand Down

0 comments on commit 5529ab5

Please sign in to comment.