SupaLidlGame/State/NPC/Doc/DocShungiteSpikeState.cs

62 lines
1.7 KiB
C#
Raw Normal View History

2023-07-17 20:03:38 -07:00
using Godot;
using SupaLidlGame.Entities;
namespace SupaLidlGame.State.NPC.Doc;
public partial class DocShungiteSpikeState : DocShungiteDartState
2023-07-17 20:03:38 -07:00
{
private float _intensity = 1;
2023-07-18 00:57:28 -07:00
public override NPCState Enter(IState<NPCState> previous)
{
// subtract from total state time by intensity
Duration = _currentDuration = 9 - 2 * Doc.Intensity;
return base.Enter(previous);
}
2023-07-17 20:03:38 -07:00
protected override Projectile SpawnProjectile(
Vector2 position,
Vector2 direction)
{
2023-07-18 00:57:28 -07:00
var projectile = base.SpawnProjectile(position, direction)
as ShungiteSpike;
projectile.GlobalRotation = 0;
projectile.Delay = 0;
projectile.ExplodeTime = 6 - 2 * Doc.Intensity;
projectile.Hitbox.Faction = projectile.Hurtbox.Faction = Doc.Faction;
2023-07-17 20:03:38 -07:00
return projectile;
}
protected override void Attack()
{
var player = _world.CurrentPlayer;
var playerPos = player.GlobalPosition;
Vector2 left = playerPos + Vector2.Left * 64;
Vector2 right = playerPos + Vector2.Right * 64;
Vector2 up = playerPos + Vector2.Up * 64;
Vector2 down = playerPos + Vector2.Down * 64;
SpawnProjectile(left, Vector2.Zero);
SpawnProjectile(right, Vector2.Zero);
SpawnProjectile(up, Vector2.Zero);
SpawnProjectile(down, Vector2.Zero);
// only attack once and stop (but keep in this state for 8 seconds)
2023-07-18 00:57:28 -07:00
_currentAttackDuration += 8;
}
public override NPCState Process(double delta)
{
if ((_currentDuration -= delta) <= 0)
{
return ChooseAttackState;
}
if ((_currentAttackDuration -= delta) <= 0)
{
Attack();
}
return null;
2023-07-17 20:03:38 -07:00
}
}