2023-05-15 00:20:17 -07:00
|
|
|
using Godot;
|
2023-05-26 22:28:08 -07:00
|
|
|
using SupaLidlGame.Characters;
|
|
|
|
using SupaLidlGame.BoundingBoxes;
|
2023-05-15 00:20:17 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
namespace SupaLidlGame.Entities;
|
|
|
|
|
|
|
|
public partial class Projectile : RigidBody2D
|
2023-05-15 00:20:17 -07:00
|
|
|
{
|
2023-08-17 22:14:06 -07:00
|
|
|
[Signal]
|
|
|
|
public delegate void HitEventHandler(BoundingBox box);
|
|
|
|
|
2023-07-21 02:54:13 -07:00
|
|
|
//public virtual Vector2 Velocity => Direction * Speed;
|
|
|
|
public virtual Vector2 Velocity
|
|
|
|
{
|
|
|
|
get => Direction * Speed;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
throw new System.NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
2023-05-26 22:28:08 -07:00
|
|
|
|
2023-07-19 00:17:25 -07:00
|
|
|
[Export]
|
|
|
|
public string ProjectileName { get; set; }
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
[Export]
|
|
|
|
public float Speed { get; set; }
|
2023-05-26 22:28:08 -07:00
|
|
|
|
2023-07-21 02:54:13 -07:00
|
|
|
[Export]
|
|
|
|
public Vector2 AccelerationDirection { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public float AccelerationMagnitude { get; set; }
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
[Export]
|
|
|
|
public Vector2 Direction { get; set; }
|
2023-05-26 22:28:08 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
[Export]
|
|
|
|
public Hitbox Hitbox { get; set; }
|
2023-05-26 22:28:08 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
[Export]
|
|
|
|
public double Lifetime { get; set; } = 10;
|
2023-06-03 14:02:40 -07:00
|
|
|
|
2023-07-13 23:46:58 -07:00
|
|
|
[Export]
|
|
|
|
public double Delay { get; set; } = 0;
|
|
|
|
|
2023-09-03 17:42:32 -07:00
|
|
|
[System.Obsolete]
|
2023-06-03 18:21:46 -07:00
|
|
|
public Character Character { get; set; }
|
2023-05-26 22:28:08 -07:00
|
|
|
|
2023-09-03 17:42:32 -07:00
|
|
|
public Items.Weapon Weapon { get; set; }
|
|
|
|
|
2023-07-19 00:17:25 -07:00
|
|
|
public bool IsDead { get; set; }
|
|
|
|
|
2023-07-13 23:46:58 -07:00
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
Hitbox.Hit += OnHit;
|
|
|
|
}
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public override void _Process(double delta)
|
|
|
|
{
|
2023-07-13 23:46:58 -07:00
|
|
|
if (Delay > 0)
|
|
|
|
{
|
|
|
|
Delay -= delta;
|
2023-07-19 00:17:25 -07:00
|
|
|
if (Delay <= 0)
|
|
|
|
{
|
|
|
|
OnDelayEnd();
|
|
|
|
}
|
2023-07-13 23:46:58 -07:00
|
|
|
}
|
2023-06-03 18:21:46 -07:00
|
|
|
if ((Lifetime -= delta) <= 0)
|
2023-06-03 14:02:40 -07:00
|
|
|
{
|
2023-07-19 00:17:25 -07:00
|
|
|
if (!IsDead)
|
|
|
|
{
|
|
|
|
Die();
|
|
|
|
}
|
2023-06-03 14:02:40 -07:00
|
|
|
}
|
2023-06-03 18:21:46 -07:00
|
|
|
}
|
2023-06-03 14:02:40 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public override void _PhysicsProcess(double delta)
|
|
|
|
{
|
2023-07-19 00:17:25 -07:00
|
|
|
if (IsDead)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-07-17 09:30:49 -07:00
|
|
|
Vector2 velocity = Delay <= 0 ? Velocity : Vector2.Zero;
|
|
|
|
MoveAndCollide(velocity * (float)delta);
|
2023-06-03 18:21:46 -07:00
|
|
|
}
|
2023-05-26 22:28:08 -07:00
|
|
|
|
2023-07-13 23:46:58 -07:00
|
|
|
public void OnHit(BoundingBox box)
|
2023-06-03 18:21:46 -07:00
|
|
|
{
|
|
|
|
if (box is Hurtbox hurtbox)
|
2023-05-26 22:28:08 -07:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
hurtbox.InflictDamage(
|
|
|
|
Hitbox.Damage,
|
2023-09-03 17:42:32 -07:00
|
|
|
Hitbox.Inflictor,
|
2023-06-03 18:21:46 -07:00
|
|
|
Hitbox.Knockback,
|
2023-09-03 17:42:32 -07:00
|
|
|
weapon: Weapon,
|
2023-06-03 18:21:46 -07:00
|
|
|
knockbackVector: Direction
|
|
|
|
);
|
2023-08-17 22:14:06 -07:00
|
|
|
EmitSignal(SignalName.Hit, box);
|
2023-05-26 22:28:08 -07:00
|
|
|
}
|
2023-05-15 00:20:17 -07:00
|
|
|
}
|
2023-07-19 00:17:25 -07:00
|
|
|
|
|
|
|
public virtual void Die()
|
|
|
|
{
|
|
|
|
QueueFree();
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void OnDelayEnd()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2023-05-15 00:20:17 -07:00
|
|
|
}
|