Переходы между днями.
This commit is contained in:
parent
7663a741e4
commit
71502b0653
7 changed files with 128 additions and 6 deletions
67
scripts/Day.cs
Normal file
67
scripts/Day.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue