newlon/scripts/Sun.cs
2025-07-19 19:03:41 +05:00

60 lines
1.5 KiB
C#

using Godot;
using Newlon.Components.Level;
namespace Newlon;
public partial class Sun : Area2D
{
public static Control Counter;
[Export] public int amount = 25;
[Export] private Timer _deathTimer;
[Export] private AnimationPlayer _rotation;
[Export] private AnimationPlayer _fade;
private bool scoring;
public override void _Ready()
{
_rotation.SpeedScale = 1.0f + GD.Randf() / 2.0f;
}
public override void _InputEvent(Viewport viewport, InputEvent @event, int shapeIdx)
{
if (Settings.SunClick == false || scoring) return;
if (@event.IsActionPressed("primary_action"))
{
ScoreSun();
}
}
public override void _Process(double delta)
{
if (scoring) return;
if (_deathTimer.TimeLeft / _deathTimer.WaitTime <= 0.25)
{
_fade.Play("main");
}
}
public override void _MouseEnter()
{
if (Settings.SunClick) return;
ScoreSun();
}
private void ScoreSun()
{
_fade.Stop();
scoring = true;
GetNode<ChannelPlayer>("SunPlayer").Play();
var tween = CreateTween();
tween.TweenInterval(0.1);
tween.TweenProperty(this, "global_position", GetCanvasTransform().AffineInverse() * (Counter.GlobalPosition + Counter.PivotOffset), 0.5).SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
tween.TweenCallback(Callable.From(() =>
{
RuntimeLevelData.Instance.AddSun(amount);
QueueFree();
}));
}
}