SupaLidlGame/State/NPC/Doc/DocShungiteSpikeState.cs

67 lines
1.8 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
{
protected int _currentAttacks = 0;
2023-07-17 20:03:38 -07:00
2023-07-18 00:57:28 -07:00
public override NPCState Enter(IState<NPCState> previous)
{
_currentAttacks = 0;
_currentAttackDuration = 1;
2023-07-18 00:57:28 -07:00
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.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;
var docPos = NPC.GlobalPosition;
var projectile = SpawnProjectile(docPos, Vector2.Zero) as ShungiteSpike;
var projectileSpeed = projectile.Speed = 96;
// predict to player's position
var targetPos = Utils.Physics.PredictNewPosition(
docPos,
projectileSpeed,
playerPos,
player.Velocity,
out float time);
projectile.Direction = projectile.GlobalPosition.DirectionTo(targetPos);
projectile.FreezeTime = time + 0.25; // freeze when it reaches target
GD.Print("projectile velocity: " + projectile.Velocity);
_currentAttackDuration = 1;
_currentAttacks++;
2023-07-18 00:57:28 -07:00
}
public override NPCState Process(double delta)
{
if ((_currentAttackDuration -= delta) <= 0)
2023-07-18 00:57:28 -07:00
{
Attack();
2023-07-18 00:57:28 -07:00
}
if (_currentAttacks >= Doc.Intensity)
2023-07-18 00:57:28 -07:00
{
return ChooseAttackState;
2023-07-18 00:57:28 -07:00
}
return null;
2023-07-17 20:03:38 -07:00
}
}