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-06-03 18:21:46 -07:00
|
|
|
public Vector2 Velocity => Direction * Speed;
|
2023-05-26 22:28:08 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
[Export]
|
|
|
|
public float Speed { get; set; }
|
2023-05-26 22:28:08 -07:00
|
|
|
|
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-06-03 18:21:46 -07:00
|
|
|
public Character Character { get; set; }
|
2023-05-26 22:28:08 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public override void _Process(double delta)
|
|
|
|
{
|
|
|
|
if ((Lifetime -= delta) <= 0)
|
2023-06-03 14:02:40 -07:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
QueueFree();
|
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)
|
|
|
|
{
|
|
|
|
Vector2 velocity = Velocity;
|
|
|
|
MoveAndCollide(velocity * (float)delta);
|
|
|
|
}
|
2023-05-26 22:28:08 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public void _on_hitbox_hit(BoundingBox box)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
Character,
|
|
|
|
Hitbox.Knockback,
|
|
|
|
knockbackVector: Direction
|
|
|
|
);
|
2023-05-26 22:28:08 -07:00
|
|
|
}
|
2023-05-15 00:20:17 -07:00
|
|
|
}
|
|
|
|
}
|