Skip to content

Commit 9f6de6a

Browse files
committed
Add damage effects
Simple animations on damage and heal Small fixes to ordering of control flow for damage and heal Standardized tweens to be on node not tree
1 parent 13bfc18 commit 9f6de6a

4 files changed

Lines changed: 69 additions & 18 deletions

File tree

scenes/BattleDirector/scripts/NotePlacementBar.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public partial class NotePlacementBar : Node
3737
//Juice - https://www.youtube.com/watch?v=LGt-jjVf-ZU
3838
private int _limiter;
3939
private Vector2 _barInitPosition;
40-
private float _randomStrength = 1f;
40+
private float _baseShake = 1f;
4141
private float _shakeFade = 10f;
4242
private RandomNumberGenerator _rng = new();
4343
private float _shakeStrength;
@@ -49,7 +49,7 @@ private void ProcessShake(double delta)
4949
return;
5050
if (_currentBarValue >= MaxValue)
5151
{
52-
_shakeStrength = _randomStrength;
52+
_shakeStrength = _baseShake;
5353
}
5454
if (_shakeStrength > 0)
5555
{

scenes/BattleDirector/scripts/TextParticle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public partial class TextParticle : Label
66
// Called when the node enters the scene tree for the first time.
77
public override void _Ready()
88
{
9-
Tween tween = GetTree().CreateTween();
9+
Tween tween = CreateTween();
1010
ZIndex = 2;
1111
Position += Vector2.Left * (GD.Randf() * 40 - 20);
1212
tween.SetTrans(Tween.TransitionType.Elastic);

scenes/ChartViewport/scripts/ChartManager.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void PrepChart(SongData songData)
6060
public void BeginTweens()
6161
{
6262
//This could be good as a function to call on something, to have many things animated to the beat.
63-
var tween = GetTree().CreateTween();
63+
var tween = CreateTween();
6464
tween
6565
.TweenMethod(
6666
Callable.From((Vector2 scale) => TweenArrows(scale)),
@@ -129,12 +129,4 @@ public void ComboText(string text, ArrowType arrow, int currentCombo)
129129
IH.FeedbackEffect(arrow, text);
130130
newText.Text = text + $" {currentCombo}";
131131
}
132-
133-
public override void _ExitTree()
134-
{
135-
foreach (var tween in GetTree().GetProcessedTweens())
136-
{
137-
tween.Stop();
138-
}
139-
}
140132
}

scenes/Puppets/scripts/PuppetTemplate.cs

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,83 @@ public override void _Ready()
4343
}
4444
}
4545

46+
public override void _Process(double delta)
47+
{
48+
ProcessShake(delta);
49+
}
50+
4651
public void Init(Texture2D texture, string name)
4752
{
4853
Sprite.Texture = texture;
4954
UniqName = name;
5055
}
5156

57+
//Juice - https://www.youtube.com/watch?v=LGt-jjVf-ZU
58+
private int _limiter;
59+
private const float BaseShake = 100f;
60+
private float _shakeFade = 10f;
61+
private float _shakeStrength;
62+
private float _baseAnimDuration = 0.1f;
63+
64+
private void ProcessShake(double delta)
65+
{
66+
_limiter = (_limiter + 1) % 3;
67+
if (_limiter != 1)
68+
return;
69+
70+
if (_shakeStrength > 0)
71+
{
72+
_shakeStrength = (float)Mathf.Lerp(_shakeStrength, 0, _shakeFade * delta);
73+
}
74+
Position =
75+
StartPos
76+
+ new Vector2(
77+
(float)GD.RandRange(-_shakeStrength, _shakeStrength),
78+
(float)GD.RandRange(-_shakeStrength, _shakeStrength)
79+
);
80+
}
81+
82+
protected virtual void DamageAnimate(int amount)
83+
{ //TODO: Make animate in time with bpm
84+
float damageAnimDir = (GetViewportRect().Size / 2 - Position).Normalized().X;
85+
float scalar = (float)amount / _maxHealth;
86+
_shakeStrength = (scalar * BaseShake);
87+
88+
Color flashColor = Colors.White * 99; //White = neutral modulate, very white is higher contrast white
89+
if (amount < 0) //If healing
90+
{
91+
flashColor = Colors.Green;
92+
damageAnimDir = 0;
93+
_shakeStrength = 0;
94+
}
95+
96+
var tween = CreateTween();
97+
tween.SetTrans(Tween.TransitionType.Spring);
98+
tween.TweenProperty(this, "modulate", flashColor, _baseAnimDuration);
99+
tween.Chain().TweenProperty(this, "modulate", Colors.White, _baseAnimDuration);
100+
tween.Parallel();
101+
tween
102+
.TweenProperty(
103+
this,
104+
"position:x",
105+
-(damageAnimDir * 2) * (2 + scalar),
106+
_baseAnimDuration
107+
)
108+
.AsRelative();
109+
tween.Chain().TweenProperty(this, "position", StartPos, 2 * _baseAnimDuration);
110+
}
111+
52112
public virtual void TakeDamage(int amount)
53113
{
54-
if (_currentHealth <= 0)
55-
return; //TEMP Only fire once.
56114
amount = Math.Max(0, amount); //Should not be able to heal from damage.
115+
if (_currentHealth <= 0 || amount == 0)
116+
return; //TEMP Only fire once.
57117
_currentHealth = _healthBar.ChangeHP(-amount);
118+
DamageAnimate(amount);
58119
if (_currentHealth <= 0)
59120
{
60121
Defeated?.Invoke(this);
61122
}
62-
63-
if (amount == 0)
64-
return;
65123
TextParticle newText = new TextParticle();
66124
newText.Modulate = Colors.Red;
67125
Sprite.AddChild(newText);
@@ -71,9 +129,10 @@ public virtual void TakeDamage(int amount)
71129
public virtual void Heal(int amount)
72130
{
73131
_currentHealth = _healthBar.ChangeHP(amount);
74-
132+
amount = Math.Max(0, amount); //Should not be able to damage from heal.
75133
if (amount == 0)
76134
return;
135+
DamageAnimate(-amount);
77136
TextParticle newText = new TextParticle();
78137
newText.Modulate = Colors.Green;
79138
Sprite.AddChild(newText);

0 commit comments

Comments
 (0)