wave flag
This commit is contained in:
parent
8287cf609a
commit
6d9edc0dc2
7 changed files with 168 additions and 26 deletions
17
scripts/gui/WaveFlag.cs
Normal file
17
scripts/gui/WaveFlag.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using Godot;
|
||||
|
||||
|
||||
public partial class WaveFlag : TextureRect
|
||||
{
|
||||
public int waveIndex;
|
||||
public double anim_time;
|
||||
public void HugeWaveApproached(int what)
|
||||
{
|
||||
if (waveIndex == what)
|
||||
{
|
||||
var tween = CreateTween().SetEase(Tween.EaseType.Out).SetTrans(Tween.TransitionType.Cubic).SetParallel();
|
||||
tween.TweenProperty(this, "anchor_top", 0.1, anim_time);
|
||||
tween.TweenProperty(this, "anchor_bottom", 0.1, anim_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
scripts/gui/WaveFlag.cs.uid
Normal file
1
scripts/gui/WaveFlag.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://06ns8r18dalm
|
||||
|
|
@ -4,8 +4,10 @@ public partial class WaveProgress : TextureProgressBar
|
|||
{
|
||||
private TextureRect head;
|
||||
private Tween tween;
|
||||
|
||||
private PackedScene flagScene = ResourceLoader.Load<PackedScene>("uid://drobbh5x1v7mi");
|
||||
[Export] private double progressTime = 2.0f;
|
||||
[Signal] public delegate void HugeWaveInitiatedEventHandler(int waveNumber);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
head = GetNode<TextureRect>("Head");
|
||||
|
|
@ -15,12 +17,31 @@ public partial class WaveProgress : TextureProgressBar
|
|||
if (Visible == false) Visible = true;
|
||||
if (tween != null) tween.Kill();
|
||||
tween = CreateTween().SetParallel(true).SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||
tween.TweenProperty(this,"value",to+1,progressTime);
|
||||
tween.TweenProperty(head,"anchor_right",1.0-(float)(to+1.0f)/MaxValue,progressTime);
|
||||
tween.TweenProperty(head,"anchor_left",1.0-(float)(to+1.0f)/MaxValue,progressTime);
|
||||
tween.TweenProperty(this, "value", to + 1, progressTime);
|
||||
tween.TweenProperty(head, "anchor_right", 1.0 - (float)(to + 1.0f) / MaxValue, progressTime);
|
||||
tween.TweenProperty(head, "anchor_left", 1.0 - (float)(to + 1.0f) / MaxValue, progressTime);
|
||||
}
|
||||
public void SetLevelData(AdventureLevelResource resource)
|
||||
{
|
||||
MaxValue = resource.waves.Count;
|
||||
for (int i = 0; i < resource.waves.Count; i++)
|
||||
{
|
||||
if (resource.waves[i].isHugeWave)
|
||||
{
|
||||
var flag = flagScene.Instantiate<WaveFlag>();
|
||||
AddChild(flag);
|
||||
flag.AnchorTop = 0.5f;
|
||||
flag.AnchorBottom = 0.5f;
|
||||
flag.AnchorLeft = 1.0f - (float)(i + 1) / resource.waves.Count;
|
||||
flag.AnchorRight = 1.0f - (float)(i + 1) / resource.waves.Count;
|
||||
flag.anim_time = progressTime;
|
||||
flag.waveIndex = i;
|
||||
HugeWaveInitiated += flag.HugeWaveApproached;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void OnHugeWaveApproached(int what)
|
||||
{
|
||||
EmitSignal(SignalName.HugeWaveInitiated, what);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,17 +6,31 @@ namespace Newlon.Components.Level;
|
|||
public partial class LevelRunner : Node
|
||||
{
|
||||
private AdventureLevelResource resource;
|
||||
private int waveIndex = -1;
|
||||
private bool hugeWaveApproaching = false;
|
||||
[Export] private RowSpawner rowSpawner;
|
||||
[Export] private Timer waveTimer;
|
||||
private int waveIndex = -1;
|
||||
[Export] private float approachNotificationTime;
|
||||
[Signal] public delegate void ResourceChangedEventHandler(AdventureLevelResource resource);
|
||||
[Signal] public delegate void WaveChangedEventHandler(int to);
|
||||
[Signal] public delegate void HugeWaveApproachingCallbackEventHandler();
|
||||
[Signal] public delegate void HugeWaveInitiatedEventHandler(int waveNumber);
|
||||
|
||||
public override void _Ready()
|
||||
public override void _Ready()
|
||||
{
|
||||
waveTimer.Timeout += SummonWave;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (waveTimer.TimeLeft < approachNotificationTime && resource.waves[waveIndex + 1].isHugeWave && hugeWaveApproaching == false)
|
||||
{
|
||||
hugeWaveApproaching = true;
|
||||
EmitSignal(SignalName.HugeWaveApproachingCallback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetLevelResource(AdventureLevelResource data)
|
||||
{
|
||||
resource = data;
|
||||
|
|
@ -29,7 +43,9 @@ public partial class LevelRunner : Node
|
|||
private void SummonWave()
|
||||
{
|
||||
waveIndex += 1;
|
||||
hugeWaveApproaching = false;
|
||||
EmitSignal(SignalName.WaveChanged, waveIndex);
|
||||
if (resource.waves[waveIndex].isHugeWave) EmitSignal(SignalName.HugeWaveInitiated, waveIndex);
|
||||
rowSpawner.Add(resource.waves[waveIndex].zombiesOrdered);
|
||||
|
||||
if (waveIndex == resource.waves.Count - 1) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue