2025-05-13 19:22:01 +08:00

187 lines
5.5 KiB
C#

using System;
using System.Collections;
using Godot;
public partial class GameOver
{
private static readonly AudioStream goTheme = GD.Load<AudioStream>("res://Audio/Music/gameover_yellow.ogg");
public static bool repeatable;
public static GameOver instance;
private const string space = "\t\t\t\t\t\t\t";
private const float x = -72f;
private const float x2 = 64f;
private static PackedScene opt = GD.Load<PackedScene>("res://Objects/UI/GameOverOpt.tscn");
public static IEnumerator DoGameOver(Vector2? soulPos = null)
{
instance = new GameOver();
float a;
for (a = 0f; a < 10f; a += Main.deltaTime)
{
yield return null;
}
Audio.music.Stop();
Room.current.ProcessMode = Node.ProcessModeEnum.Disabled;
if (BattleDR.current != null)
{
BattleDR.current.Visible = false;
soulPos = DWMenu.instance.soulBody.GlobalPosition;
}
else
{
soulPos.GetValueOrDefault();
if (!soulPos.HasValue)
{
Vector2 value = Player.instance.GlobalPosition + new Vector2(0f, -16f);
soulPos = value;
}
}
DWMenu.instance.Visible = false;
CameraController.instance.cover.SelfModulate = Main.colorBlack;
CameraController.instance.cover.Visible = true;
Control cover = CameraController.instance.cover;
Sprite2D node;
Sprite2D soul = (node = new Sprite2D
{
Texture = GD.Load<Texture2D>("res://Sprites/Menus/Menu Sprites/Soul.tres"),
SelfModulate = Main.colorYellow
});
cover.AddChild(node, forceReadableName: false, Node.InternalMode.Disabled);
soul.GlobalPosition = soulPos.Value;
for (a = 0f; a < 30f; a += Main.deltaTime)
{
yield return null;
}
Audio.PlaySound("snd_break1.wav");
soul.Texture = GD.Load<Texture2D>("res://Sprites/Menus/Menu Sprites/SoulBreak.tres");
for (a = 0f; a < 60f; a += Main.deltaTime)
{
yield return null;
}
Audio.PlaySound("snd_break2.wav");
((Node2D)Main.Particle("SoulBreak", soul.Position, 4096, CameraController.instance)).GlobalPosition = soul.GlobalPosition;
soul.Free();
for (a = 0f; a < 120f; a += Main.deltaTime)
{
yield return null;
}
Audio.ChangeMusic(goTheme);
Control cover2 = CameraController.instance.cover;
soul = (node = new Sprite2D
{
Texture = GD.Load<Texture2D>("res://Sprites/Menus/Menu Sprites/GameOver.tres"),
Position = new Vector2(204f, 135f),
SelfModulate = Main.colorClear
});
cover2.AddChild(node, forceReadableName: false, Node.InternalMode.Disabled);
a = 0f;
for (float b = 80f; a <= b + 1f; a += Main.deltaTime)
{
soul.SelfModulate = Main.colorClear.Lerp(Main.colorWhite, Mathf.Min(a / b, 1f));
yield return null;
}
Control o = opt.Instantiate<Control>(PackedScene.GenEditState.Disabled);
o.Modulate = Main.colorClear;
soul.AddChild(o, forceReadableName: false, Node.InternalMode.Disabled);
o.Position = new Vector2(0f, 50f);
Node2D s = o.GetChild<Node2D>(0);
RichTextLabel text = o.GetChild<RichTextLabel>(1);
text.Text = "[center]" + Texts.common[52] + "\t\t\t\t\t\t\t" + Texts.common[53];
text.AnchorsPreset = 7;
int option = -1;
float gcCD = 0f;
while (true)
{
o.Modulate = o.Modulate.Lerp(Main.colorWhite, Main.deltaTime * 0.15f);
if (option != -1)
{
MoveSoul(s, in option);
}
if (Input.IsActionJustPressed(Main.keys[2]))
{
option = 0;
text.Text = "[center][color=yellow]" + Texts.common[52] + "[/color]\t\t\t\t\t\t\t" + Texts.common[53];
}
else if (Input.IsActionJustPressed(Main.keys[3]))
{
option = 1;
text.Text = "[center]" + Texts.common[52] + "\t\t\t\t\t\t\t[color=yellow]" + Texts.common[53];
}
else if (Input.IsActionJustPressed(Main.keys[4]))
{
switch (option)
{
case 0:
{
Audio.ChangeMusic((Audio.AudioBlock)null, 3f);
AudioStreamPlayer sound = Audio.PlaySound("snd_dtrans_lw.ogg");
CameraController.Transition(Main.colorWhite, 180f);
float b = 0f;
for (a = 180f; b < a; b += Main.deltaTime)
{
soul.Modulate = Main.colorWhite.Lerp(Main.colorClear, b / a);
MoveSoul(s, in option);
yield return null;
}
while (sound.Playing)
{
yield return null;
}
if (BattleDR.current != null)
{
BattleDR.Abort(nullify: false);
}
if (FightingGame.instance != null)
{
Room.current.ProcessMode = Node.ProcessModeEnum.Inherit;
FightingGame.instance.Start();
CameraController.Transition(Main.colorClearB, 10f);
}
else if (repeatable)
{
Coroutine.Start(BattleDR.StartBattle(null, BattleDR.reloadStats.Value.bg, BattleDR.reloadStats.Value.enemies, null, BattleDR.reloadStats.Value.mes, BattleDR.reloadStats.Value.audioBlock, quickIntro: true));
}
else
{
CameraController.instance.GlobalPosition = Vector2.Zero;
MainMenu.forceReload = SaveFile.current.slot;
Main.instance.GetTree().ReloadCurrentScene();
}
soul.QueueFree();
yield break;
}
case 1:
Audio.ChangeMusic((Audio.AudioBlock)null, 3f);
for (a = 0f; a < 180f; a += Main.deltaTime)
{
soul.SelfModulate = Main.colorWhite.Lerp(Main.colorClear, a / 180f);
o.Modulate = o.Modulate.Lerp(Main.colorClear, Main.deltaTime * 0.15f);
yield return null;
}
CameraController.instance.GlobalPosition = Vector2.Zero;
Main.instance.GetTree().ReloadCurrentScene();
yield break;
}
}
gcCD += Main.deltaTime;
if (gcCD > 120f)
{
gcCD = 0f;
GC.Collect();
}
yield return null;
}
}
private static void MoveSoul(Node2D s, in int option)
{
s.Position = s.Position.Lerp(new Vector2((option == 0) ? (-72f) : 64f, s.Position.Y), Main.deltaTime * 0.2f);
}
}