Stat bar and timer
This commit is contained in:
@@ -3,9 +3,7 @@ using Chickensoft.Collections;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace GameJamDungeon
|
||||
{
|
||||
@@ -65,11 +63,21 @@ namespace GameJamDungeon
|
||||
|
||||
[Node] public IHitbox Hitbox { get; set; } = default!;
|
||||
|
||||
[Node] public Timer HealthTimer { get; set; } = default!;
|
||||
|
||||
[Node] public Label HPNumber { get; set; } = default!;
|
||||
|
||||
[Node] public Label VTNumber { get; set; } = default!;
|
||||
|
||||
[Node] public ProgressBar HPBar { get; set; } = default!;
|
||||
|
||||
[Node] public ProgressBar VTBar { get; set; } = default!;
|
||||
|
||||
private IAutoProp<WeaponInfo> EquippedWeapon { get; set; } = default!;
|
||||
|
||||
private AutoProp<double> _currentHP { get; set; } = default!;
|
||||
|
||||
private IAutoProp<int> _currentVT { get; set; } = default!;
|
||||
private AutoProp<int> _currentVT { get; set; } = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -88,10 +96,22 @@ namespace GameJamDungeon
|
||||
PlayerLogic.Set(PlayerData);
|
||||
|
||||
GameRepo.SetPlayerGlobalPosition(GlobalPosition);
|
||||
GameRepo.PlayerGlobalPosition.Sync += OnPlayerPositionUpdated;
|
||||
|
||||
EquippedWeapon = new AutoProp<WeaponInfo>(WeaponInfo.Default);
|
||||
EquippedWeapon.Sync += OnEquippedWeaponChanged;
|
||||
|
||||
_currentHP = new AutoProp<double>(PlayerStatInfo.MaximumHP);
|
||||
_currentVT = new AutoProp<int>(PlayerStatInfo.MaximumVT);
|
||||
GameRepo.PlayerGlobalPosition.Sync += OnPlayerPositionUpdated;
|
||||
_currentHP.Sync += OnHPChanged;
|
||||
_currentVT.Sync += OnVTChanged;
|
||||
|
||||
HPBar.MaxValue = PlayerStatInfo.MaximumHP;
|
||||
HPBar.Value = _currentHP.Value;
|
||||
VTBar.MaxValue = PlayerStatInfo.MaximumVT;
|
||||
VTBar.Value = _currentVT.Value;
|
||||
|
||||
HealthTimer.Timeout += OnHealthTimerTimeout;
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
@@ -116,8 +136,6 @@ namespace GameJamDungeon
|
||||
this.Provide();
|
||||
PlayerLogic.Start();
|
||||
|
||||
EquippedWeapon.Sync += OnEquippedWeaponChanged;
|
||||
_currentHP.Sync += OnHPChanged;
|
||||
SwordSlashAnimation.Position = GetViewport().GetVisibleRect().Size / 2;
|
||||
}
|
||||
|
||||
@@ -178,10 +196,27 @@ namespace GameJamDungeon
|
||||
|
||||
private void OnHPChanged(double newHP)
|
||||
{
|
||||
HPNumber.Text = Mathf.RoundToInt(newHP).ToString();
|
||||
HPBar.Value = newHP;
|
||||
|
||||
if (newHP <= 0.0)
|
||||
PlayerLogic.Input(new PlayerLogic.Input.Killed());
|
||||
}
|
||||
|
||||
private void OnVTChanged(int newVT)
|
||||
{
|
||||
VTNumber.Text = newVT.ToString();
|
||||
VTBar.Value = newVT;
|
||||
}
|
||||
|
||||
private void OnPlayerPositionUpdated(Vector3 globalPosition) => GlobalPosition = globalPosition;
|
||||
|
||||
private void OnHealthTimerTimeout()
|
||||
{
|
||||
if (_currentVT.Value > 0)
|
||||
_currentVT.OnNext(_currentVT.Value - 1);
|
||||
else
|
||||
_currentHP.OnNext(_currentHP.Value - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user