chill-jam-10-2024/scripts/Day.cs

67 lines
1.6 KiB
C#

using Godot;
using System;
public partial class Day : Node2D
{
[Export] public string NextScene;
private enum State
{
Default,
TransitionIn,
TransitionOut
}
private State _state = State.TransitionIn;
private Player _player;
private ColorRect _colorRect;
private AudioStreamPlayer _music;
private double _transitionTimeout = 0;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_player = (Player)FindChild("Player");
_colorRect = (ColorRect)FindChild("ColorRect");
_music = (AudioStreamPlayer)FindChild("Music");
_colorRect.Color = new Color(0, 0, 0, 1f);
_music.VolumeDb = -40;
_player.CurrentState = Player.State.Wait;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if (_state == State.TransitionIn)
{
if (_transitionTimeout <= 2)
{
_transitionTimeout += delta;
_music.VolumeDb = Mathf.Lerp(-40, 0, (float)_transitionTimeout/2);
_colorRect.Color = new Color(0, 0, 0, Mathf.Lerp(1, 0, (float)_transitionTimeout/2));
}
else
{
_state = State.Default;
_player.CurrentState = Player.State.Normal;
_transitionTimeout = 0;
}
}
if (_state == State.TransitionOut)
{
_player.CurrentState = Player.State.Wait;
if (_transitionTimeout <= 2)
{
_transitionTimeout += delta;
_music.VolumeDb = Mathf.Lerp(0, -40, (float)_transitionTimeout/2);
_colorRect.Color = new Color(0, 0, 0, Mathf.Lerp(0, 1, (float)_transitionTimeout/2));
}
else
{
GetNode<SceneManager>("/root/SceneManager").SwitchScene("Day1");
}
}
}
}