Implement even more inventory/UI stuff
This commit is contained in:
@@ -73,12 +73,10 @@ namespace GameJamDungeon
|
||||
|
||||
[Node] public Label VTNumber { get; set; } = default!;
|
||||
|
||||
[Node] public Label LevelNumber { get; set; } = default!;
|
||||
|
||||
[Node] public IArea3D CollisionDetector { get; set; } = default!;
|
||||
|
||||
private AutoProp<double> _currentHP { get; set; } = default!;
|
||||
|
||||
private AutoProp<int> _currentVT { get; set; } = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
AnimationPlayer.AnimationFinished += OnAnimationFinished;
|
||||
@@ -100,11 +98,6 @@ namespace GameJamDungeon
|
||||
|
||||
GameRepo.SetPlayerStatInfo(PlayerStatInfo);
|
||||
|
||||
_currentHP = new AutoProp<double>(PlayerStatInfo.MaximumHP);
|
||||
_currentVT = new AutoProp<int>(PlayerStatInfo.MaximumVT);
|
||||
_currentHP.Sync += OnHPChanged;
|
||||
_currentVT.Sync += OnVTChanged;
|
||||
|
||||
HealthTimer.Timeout += OnHealthTimerTimeout;
|
||||
CollisionDetector.AreaEntered += OnEnemyHitBoxEntered;
|
||||
}
|
||||
@@ -125,8 +118,6 @@ namespace GameJamDungeon
|
||||
var attackSpeed = (float)weaponInfo.AttackSpeed;
|
||||
AnimationPlayer.SetSpeedScale(attackSpeed);
|
||||
AnimationPlayer.Play("attack");
|
||||
if (weaponInfo.WeaponTags.Contains(WeaponTag.SelfDamage))
|
||||
_currentHP.OnNext(_currentHP.Value - 5);
|
||||
})
|
||||
.Handle((in PlayerLogic.Output.ThrowItem output) =>
|
||||
{
|
||||
@@ -153,7 +144,7 @@ namespace GameJamDungeon
|
||||
{
|
||||
if (area is IHitbox hitBox)
|
||||
{
|
||||
if (_currentHP.Value > 0)
|
||||
if (GameRepo.PlayerStatInfo.Value.CurrentHP > 0)
|
||||
{
|
||||
var enemy = hitBox.GetParent<IEnemy>();
|
||||
var isCriticalHit = false;
|
||||
@@ -162,8 +153,8 @@ namespace GameJamDungeon
|
||||
var roll = rng.Randf();
|
||||
if (roll <= enemy.EnemyStatInfo.Luck)
|
||||
isCriticalHit = true;
|
||||
var damage = DamageCalculator.CalculateEnemyDamage(hitBox.Damage, PlayerStatInfo, enemy.EnemyStatInfo, GameRepo.EquippedArmor.Value.ArmorInfo, isCriticalHit);
|
||||
_currentHP.OnNext(_currentHP.Value - damage);
|
||||
var damage = DamageCalculator.CalculateEnemyDamage(PlayerStatInfo, enemy.EnemyStatInfo, GameRepo.EquippedArmor.Value.ArmorInfo, isCriticalHit);
|
||||
GameRepo.PlayerStatInfo.Value.CurrentHP = GameRepo.PlayerStatInfo.Value.CurrentHP - damage;
|
||||
GD.Print($"Player hit for {damage} damage.");
|
||||
}
|
||||
}
|
||||
@@ -178,6 +169,13 @@ namespace GameJamDungeon
|
||||
PlayerLogic.Input(new PlayerLogic.Input.Moved(GlobalPosition));
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
OnHPChanged(GameRepo.PlayerStatInfo.Value.CurrentHP);
|
||||
OnVTChanged(GameRepo.PlayerStatInfo.Value.CurrentVT);
|
||||
OnLevelChanged(GameRepo.PlayerStatInfo.Value.CurrentLevel);
|
||||
}
|
||||
|
||||
public Vector3 GetGlobalInputVector()
|
||||
{
|
||||
var rawInput = Input.GetVector(GameInputs.MoveLeft, GameInputs.MoveRight, GameInputs.MoveUp, GameInputs.MoveDown);
|
||||
@@ -224,8 +222,6 @@ namespace GameJamDungeon
|
||||
AnimationPlayer.AnimationFinished -= OnAnimationFinished;
|
||||
}
|
||||
|
||||
private void OnEquippedWeaponChanged(Weapon info) => Hitbox.Damage = info.WeaponInfo.Damage;
|
||||
|
||||
private void OnHPChanged(double newHP)
|
||||
{
|
||||
HPNumber.Text = $"{Mathf.RoundToInt(newHP)}/{PlayerStatInfo.MaximumHP}";
|
||||
@@ -242,14 +238,19 @@ namespace GameJamDungeon
|
||||
VTNumber.Text = $"{newVT}/{PlayerStatInfo.MaximumVT}";
|
||||
}
|
||||
|
||||
private void OnLevelChanged(int newLevel)
|
||||
{
|
||||
LevelNumber.Text = $"{newLevel}";
|
||||
}
|
||||
|
||||
private void OnPlayerPositionUpdated(Vector3 globalPosition) => GlobalPosition = globalPosition;
|
||||
|
||||
private void OnHealthTimerTimeout()
|
||||
{
|
||||
if (_currentVT.Value > 0)
|
||||
_currentVT.OnNext(_currentVT.Value - 1);
|
||||
if (GameRepo.PlayerStatInfo.Value.CurrentVT > 0)
|
||||
GameRepo.PlayerStatInfo.Value.CurrentVT = GameRepo.PlayerStatInfo.Value.CurrentVT - 1;
|
||||
else
|
||||
_currentHP.OnNext(_currentHP.Value - 1);
|
||||
GameRepo.PlayerStatInfo.Value.CurrentHP = GameRepo.PlayerStatInfo.Value.CurrentHP - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user