From 7d4eac9474dec11ecc7efe22587a2bb1ad5ed2e4 Mon Sep 17 00:00:00 2001 From: Maksim Chugunov Date: Fri, 17 Jan 2025 14:01:00 +0300 Subject: [PATCH] Pain vfx --- assets/ron/animation/pain_vfx.ron | 5 ++++ src/resources/battle.rs | 50 +++++++++++++++---------------- 2 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 assets/ron/animation/pain_vfx.ron diff --git a/assets/ron/animation/pain_vfx.ron b/assets/ron/animation/pain_vfx.ron new file mode 100644 index 00000000..0e6950b6 --- /dev/null +++ b/assets/ron/animation/pain_vfx.ron @@ -0,0 +1,5 @@ +[ + Spawn( + ([Alpha(Sub(One, Var(t))), ScaleRect(Sum(Var(t), One)), Circle(F(1.0))]), + ), +] \ No newline at end of file diff --git a/src/resources/battle.rs b/src/resources/battle.rs index 4e485e7e..be9e8ce1 100644 --- a/src/resources/battle.rs +++ b/src/resources/battle.rs @@ -66,22 +66,16 @@ impl BattleAction { let applied = match self { BattleAction::Strike(a, b) => { let strike_anim = animations().get("strike").unwrap(); - match battle.apply_animation( + battle.apply_animation( Context::default() .set_owner(*a) .set_target(*b) .set_var(VarName::position, vec2(0.0, 0.0).into()) .take(), strike_anim, - ) { - Ok(_) => {} - Err(e) => error!("Animation error: {e}"), - } + ); let strike_vfx = animations().get("strike_vfx").unwrap(); - match battle.apply_animation(Context::default(), strike_vfx) { - Ok(_) => {} - Err(e) => error!("Animation error: {e}"), - } + battle.apply_animation(Context::default(), strike_vfx); let pwr = battle.world.get::(*a).unwrap().pwr; let action_a = Self::Damage(*a, *b, pwr); let pwr = battle.world.get::(*b).unwrap().pwr; @@ -95,29 +89,33 @@ impl BattleAction { true } BattleAction::Damage(_, b, x) => { - let text = animations().get("text").unwrap(); let pos = Context::new_battle_simulation(&battle) .set_owner(*b) .get_var(VarName::position) .unwrap(); - match battle.apply_animation( + let text = animations().get("text").unwrap(); + battle.apply_animation( Context::default() .set_var(VarName::text, (-*x).to_string().into()) .set_var(VarName::color, RED.into()) - .set_var(VarName::position, pos) + .set_var(VarName::position, pos.clone()) .take(), text, - ) { - Ok(_) => {} - Err(e) => error!("Animation error: {e}"), + ); + if *x > 0 { + let pain = animations().get("pain_vfx").unwrap(); + battle.apply_animation( + Context::default().set_var(VarName::position, pos).take(), + pain, + ); + let hp = battle.world.get::(*b).unwrap().hp - x; + add_actions.push(Self::VarSet( + *b, + NodeKind::UnitStats, + VarName::hp, + hp.into(), + )); } - let hp = battle.world.get::(*b).unwrap().hp - x; - add_actions.push(Self::VarSet( - *b, - NodeKind::UnitStats, - VarName::hp, - hp.into(), - )); true } BattleAction::VarSet(entity, kind, var, value) => { @@ -205,9 +203,11 @@ impl BattleSimulation { slots: 5, } } - fn apply_animation(&mut self, context: Context, anim: &Anim) -> Result<(), ExpressionError> { - anim.apply(&mut self.t, context, &mut self.world)?; - Ok(()) + fn apply_animation(&mut self, context: Context, anim: &Anim) { + match anim.apply(&mut self.t, context, &mut self.world) { + Ok(_) => {} + Err(e) => error!("Animation error: {e}"), + } } fn process_actions(&mut self, mut actions: VecDeque) { while let Some(a) = actions.pop_front() {