Slightly rework death screen

This commit is contained in:
2025-03-07 23:08:08 -08:00
parent 8a61104868
commit 84570fe87d
9 changed files with 23 additions and 17 deletions

View File

@@ -15,17 +15,21 @@ public partial class GameLogic
var gameRepo = Get<IGameRepo>(); var gameRepo = Get<IGameRepo>();
gameRepo.IsPaused.Sync += OnIsPaused; gameRepo.IsPaused.Sync += OnIsPaused;
gameRepo.DoubleExpTimeStart += OnDoubleExpTimeStart; gameRepo.DoubleExpTimeStart += OnDoubleExpTimeStart;
gameRepo.Ended += OnGameEnded;
}); });
OnDetach(() => OnDetach(() =>
{ {
var gameRepo = Get<IGameRepo>(); var gameRepo = Get<IGameRepo>();
gameRepo.IsPaused.Sync -= OnIsPaused; gameRepo.IsPaused.Sync -= OnIsPaused;
gameRepo.DoubleExpTimeStart -= OnDoubleExpTimeStart; gameRepo.DoubleExpTimeStart -= OnDoubleExpTimeStart;
gameRepo.Ended -= OnGameEnded;
}); });
} }
private void OnDoubleExpTimeStart(int lengthOfTimeInSeconds) => Output(new Output.DoubleExpTimeStart(lengthOfTimeInSeconds)); private void OnDoubleExpTimeStart(int lengthOfTimeInSeconds) => Output(new Output.DoubleExpTimeStart(lengthOfTimeInSeconds));
private void OnGameEnded() => Output(new Output.ShowLostScreen());
public void OnIsPaused(bool isPaused) => Output(new Output.SetPauseMode(isPaused)); public void OnIsPaused(bool isPaused) => Output(new Output.SetPauseMode(isPaused));
} }
} }

View File

@@ -38,6 +38,8 @@ public interface IGameRepo : IDisposable
public void CloseInventory(); public void CloseInventory();
public void GameEnded();
public double ExpRate { get; } public double ExpRate { get; }
} }
@@ -109,7 +111,7 @@ public class GameRepo : IGameRepo
CloseInventoryEvent?.Invoke(); CloseInventoryEvent?.Invoke();
} }
public void OnGameEnded() public void GameEnded()
{ {
Pause(); Pause();
Ended?.Invoke(); Ended?.Invoke();

View File

@@ -8,20 +8,20 @@ public partial class GameLogic
{ {
[Meta] [Meta]
public partial record Playing : State, public partial record Playing : State,
IGet<Input.GameOver>,
IGet<Input.AskForTeleport>, IGet<Input.AskForTeleport>,
IGet<Input.PauseGame>, IGet<Input.PauseGame>,
IGet<Input.GoToOverworld> IGet<Input.GoToOverworld>
{ {
public Playing() public Playing()
{ {
OnAttach(() => Output(new Output.StartGame())); OnAttach(() =>
{
Output(new Output.StartGame());
});
} }
public void OnEnded() => Input(new Input.GameOver()); public void OnEnded() => Input(new Input.GameOver());
public Transition On(in Input.GameOver input) => To<Quit>();
public Transition On(in Input.AskForTeleport input) => To<AskForTeleport>(); public Transition On(in Input.AskForTeleport input) => To<AskForTeleport>();
public Transition On(in Input.PauseGame input) => To<Paused>(); public Transition On(in Input.PauseGame input) => To<Paused>();

View File

@@ -16,6 +16,6 @@ public partial class PlayerLogic
public readonly record struct AttackAnimationFinished; public readonly record struct AttackAnimationFinished;
public readonly record struct Killed; public readonly record struct Die;
} }
} }

View File

@@ -1,6 +1,4 @@
using System.Numerics; namespace Zennysoft.Game.Ma.Implementation;
namespace Zennysoft.Game.Ma.Implementation;
public partial class PlayerLogic public partial class PlayerLogic
{ {

View File

@@ -8,7 +8,7 @@ public partial class PlayerLogic
public partial record State public partial record State
{ {
[Meta, Id("player_logic_alive")] [Meta, Id("player_logic_alive")]
public abstract partial record Alive : State, IGet<Input.PhysicsTick>, IGet<Input.Killed> public abstract partial record Alive : State, IGet<Input.PhysicsTick>, IGet<Input.Die>
{ {
public virtual Transition On(in Input.PhysicsTick input) public virtual Transition On(in Input.PhysicsTick input)
{ {
@@ -17,9 +17,10 @@ public partial class PlayerLogic
return ToSelf(); return ToSelf();
} }
public Transition On(in Input.Killed input) public Transition On(in Input.Die input)
{ {
GD.Print("Player died"); GD.Print("Player died");
Get<IGameRepo>().GameEnded();
return To<Dead>(); return To<Dead>();
} }
} }

View File

@@ -9,9 +9,9 @@
script = ExtResource("2_oln85") script = ExtResource("2_oln85")
CurrentHP = 30.0 CurrentHP = 30.0
MaximumHP = 0 MaximumHP = 0
CurrentAttack = 12 CurrentAttack = 15
CurrentDefense = 7 CurrentDefense = 7
MaxAttack = 12 MaxAttack = 15
MaxDefense = 7 MaxDefense = 7
ExpFromDefeat = 15 ExpFromDefeat = 15
Luck = 0.05 Luck = 0.05

View File

@@ -8,10 +8,10 @@
[sub_resource type="Resource" id="Resource_xhsah"] [sub_resource type="Resource" id="Resource_xhsah"]
script = ExtResource("2_wrps7") script = ExtResource("2_wrps7")
CurrentHP = 50.0 CurrentHP = 50.0
MaximumHP = 50.0 MaximumHP = 0
CurrentAttack = 0 CurrentAttack = 15
CurrentDefense = 0 CurrentDefense = 0
MaxAttack = 0 MaxAttack = 15
MaxDefense = 0 MaxDefense = 0
ExpFromDefeat = 0 ExpFromDefeat = 0
Luck = 0.05 Luck = 0.05

View File

@@ -150,6 +150,7 @@ public partial class Player : CharacterBody3D, IPlayer
PlayerLogic.Set(this as IPlayer); PlayerLogic.Set(this as IPlayer);
PlayerLogic.Set(Settings); PlayerLogic.Set(Settings);
PlayerLogic.Set(Stats); PlayerLogic.Set(Stats);
PlayerLogic.Set(_gameRepo);
var defaultWeapon = new Weapon(); var defaultWeapon = new Weapon();
defaultWeapon.ItemStats = _defaultWeapon; defaultWeapon.ItemStats = _defaultWeapon;
@@ -387,7 +388,7 @@ public partial class Player : CharacterBody3D, IPlayer
Stats.SetCurrentExp(newCurrentExp); Stats.SetCurrentExp(newCurrentExp);
} }
public void Die() => PlayerLogic.Input(new PlayerLogic.Input.Killed()); public void Die() => PlayerLogic.Input(new PlayerLogic.Input.Die());
public override void _UnhandledInput(InputEvent @event) public override void _UnhandledInput(InputEvent @event)
{ {