59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using Godot;
|
|
|
|
public partial class Projectile : Node3D
|
|
{
|
|
[Export]
|
|
public double Cooldown { get; protected set; }
|
|
|
|
[Export]
|
|
protected float _projectileSpeed = 1f;
|
|
|
|
[Export]
|
|
public AudioStream _soundEffect;
|
|
|
|
[Export]
|
|
public AudioStream _onHitSfx;
|
|
|
|
[Export]
|
|
public RigidBody3D _hitBox;
|
|
|
|
[Export]
|
|
public bool HasRotation = false;
|
|
|
|
public override void _Ready()
|
|
{
|
|
Speed = _projectileSpeed;
|
|
var sfxPlayer = GetTree().Root.GetNode<AudioStreamPlayer>("Main/SFXPlayer");
|
|
sfxPlayer.Stream = _soundEffect;
|
|
sfxPlayer.Play();
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
var pathFollow = GetNode<PathFollow3D>("PathFollow3D");
|
|
pathFollow.Progress += Speed * (float)delta;
|
|
if (pathFollow.ProgressRatio > 0.98f)
|
|
QueueFree();
|
|
}
|
|
|
|
public void OnProjectileHit(Node node)
|
|
{
|
|
SetProcess(false);
|
|
if (node is BasicEnemy basicEnemy && basicEnemy.HasMethod(BasicEnemy.MethodName.OnEnemyHit))
|
|
{
|
|
basicEnemy.Call(BasicEnemy.MethodName.OnEnemyHit, node);
|
|
GD.Print("Hit enemy at " + basicEnemy.Position);
|
|
}
|
|
else
|
|
GD.Print("Hit something other than enemy: " + node.Name);
|
|
|
|
_hitBox.QueueFree();
|
|
|
|
var sfxPlayer = GetTree().Root.GetNode<AudioStreamPlayer>("Main/SFXPlayer");
|
|
if (!sfxPlayer.Playing)
|
|
sfxPlayer.Play();
|
|
}
|
|
|
|
public float Speed { get; private set; }
|
|
}
|