1bit-game-jam/scripts/DeathScreen.cs

59 lines
1.6 KiB
C#

using Godot;
public partial class DeathScreen : TextureRect
{
public static DeathScreen Instance { get; private set; }
[Export] public GameCamera Camera;
private Timer _timer;
private TextureRect _playerSprite;
private TextureRect _monsterSprite;
public override void _Ready()
{
Instance = this;
Visible = false;
_timer = (Timer)FindChild("Timer");
_playerSprite = (TextureRect)FindChild("PlayerSprite");
_monsterSprite = (TextureRect)FindChild("MonsterSprite");
}
public void Timeout()
{
GD.Print("Timer end");
GetTree().ReloadCurrentScene();
}
public void Killed(Node2D killer)
{
GD.Print($"DeathScreen {killer is null}");
_playerSprite.Position = Player.Instance.Position - Camera.Position + Constants.HalfScreenSize;
_monsterSprite.Position = killer.Position - Camera.Position + Constants.HalfScreenSize;
if (Player.Instance.FindChild("AnimatedSprite2D") is AnimatedSprite2D animatedSprite2D)
{
GD.Print("Found AnimatedSprite2D for Player");
_playerSprite.Texture =
animatedSprite2D.SpriteFrames.GetFrameTexture(animatedSprite2D.Animation, animatedSprite2D.Frame);
_playerSprite.Position -= _playerSprite.Texture.GetSize() / 2;
}
if (killer.FindChild("AnimatedSprite2D") is AnimatedSprite2D killerAnimatedSprite2D)
{
GD.Print("Found AnimatedSprite2D for Monster");
_monsterSprite.Texture =
killerAnimatedSprite2D.SpriteFrames.GetFrameTexture(killerAnimatedSprite2D.Animation, killerAnimatedSprite2D.Frame);
_monsterSprite.Position -= _monsterSprite.Texture.GetSize() / 2;
}
Visible = true;
_timer.Start();
GD.Print("Timer start");
}
}