Add hit animations and death for bosses
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
@@ -12,6 +13,8 @@ namespace GameJamDungeon
|
||||
public Timer AttackTimer { get; }
|
||||
|
||||
public void Activate();
|
||||
|
||||
public AutoProp<double> CurrentHP { get; }
|
||||
}
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
@@ -21,6 +24,8 @@ namespace GameJamDungeon
|
||||
|
||||
public IBossLogic BossLogic { get; set; } = default!;
|
||||
|
||||
[Export] public EnemyStatResource BossResource { get; set; } = default!;
|
||||
|
||||
IBossLogic IProvide<IBossLogic>.Value() => BossLogic;
|
||||
|
||||
public BossLogic.IBinding BossBinding { get; set; } = default!;
|
||||
@@ -31,6 +36,12 @@ namespace GameJamDungeon
|
||||
|
||||
[Node] public Timer AttackTimer { get; set; } = default!;
|
||||
|
||||
[Node] public AnimationPlayer HitAnimation { get; set; } = default!;
|
||||
|
||||
[Node] public Area3D Hitbox { get; set; } = default!;
|
||||
|
||||
public AutoProp<double> CurrentHP { get; set; }
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
BossLogic = new BossLogic();
|
||||
@@ -44,10 +55,38 @@ namespace GameJamDungeon
|
||||
public void OnResolved()
|
||||
{
|
||||
BossBinding = BossLogic.Bind();
|
||||
BossBinding
|
||||
.Handle((in BossLogic.Output.HitByPlayer output) =>
|
||||
{
|
||||
|
||||
})
|
||||
.Handle((in BossLogic.Output.Defeated output) =>
|
||||
{
|
||||
QueueFree();
|
||||
});
|
||||
this.Provide();
|
||||
BossLogic.Start();
|
||||
CurrentHP = new AutoProp<double>(BossResource.MaximumHP);
|
||||
CurrentHP.Sync += OnHPChanged;
|
||||
AttackTimer.Timeout += AttackTimer_Timeout;
|
||||
Hitbox.AreaEntered += Hitbox_AreaEntered;
|
||||
}
|
||||
|
||||
private void Hitbox_AreaEntered(Area3D area)
|
||||
{
|
||||
if (area is IHitbox)
|
||||
{
|
||||
HitAnimation.Play("Hit");
|
||||
var isCriticalHit = false;
|
||||
var rng = new RandomNumberGenerator();
|
||||
rng.Randomize();
|
||||
var roll = rng.Randf();
|
||||
if (roll <= GameRepo.PlayerData.Inventory.EquippedWeapon.Value.WeaponStats.Luck)
|
||||
isCriticalHit = true;
|
||||
var damage = DamageCalculator.CalculateWeaponAttackDamage(GameRepo.PlayerData.CurrentAttack.Value + GameRepo.PlayerData.BonusAttack, BossResource, GameRepo.PlayerData.Inventory.EquippedWeapon.Value.WeaponStats, isCriticalHit);
|
||||
GD.Print($"Enemy Hit for {damage} damage.");
|
||||
BossLogic.Input(new BossLogic.Input.HitByPlayer(damage));
|
||||
}
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
@@ -71,5 +110,11 @@ namespace GameJamDungeon
|
||||
BossLogic.Input(new BossLogic.Input.PhysicsTick(delta));
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
private void OnHPChanged(double newHP)
|
||||
{
|
||||
if (newHP <= 0)
|
||||
BossLogic.Input(new BossLogic.Input.BossDefeated());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user