Basic enemy attack pattern
This commit is contained in:
@@ -73,6 +73,8 @@ namespace GameJamDungeon
|
||||
|
||||
[Node] public ProgressBar VTBar { get; set; } = default!;
|
||||
|
||||
[Node] public IArea3D CollisionDetector { get; set; } = default!;
|
||||
|
||||
private IAutoProp<WeaponInfo> EquippedWeapon { get; set; } = default!;
|
||||
|
||||
private AutoProp<double> _currentHP { get; set; } = default!;
|
||||
@@ -112,6 +114,7 @@ namespace GameJamDungeon
|
||||
VTBar.Value = _currentVT.Value;
|
||||
|
||||
HealthTimer.Timeout += OnHealthTimerTimeout;
|
||||
CollisionDetector.AreaEntered += OnEnemyHitBoxEntered;
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
@@ -144,6 +147,20 @@ namespace GameJamDungeon
|
||||
SetPhysicsProcess(true);
|
||||
}
|
||||
|
||||
private void OnEnemyHitBoxEntered(Area3D area)
|
||||
{
|
||||
if (area is IHitbox hitBox)
|
||||
{
|
||||
if (_currentHP.Value > 0)
|
||||
{
|
||||
var enemy = hitBox.GetParent<IEnemy>();
|
||||
var damage = DamageCalculator.CalculateEnemyDamage(hitBox.Damage, PlayerStatInfo, enemy.EnemyStatInfo);
|
||||
_currentHP.OnNext(_currentHP.Value - damage);
|
||||
GD.Print($"Player hit for {damage} damage.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPhysicsProcess(double delta)
|
||||
{
|
||||
PlayerLogic.Input(new PlayerLogic.Input.PhysicsTick(delta));
|
||||
|
||||
Reference in New Issue
Block a user