75 lines
1.5 KiB
C#
75 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Bullets/MoveTowardsPlayer.cs")]
|
|
public partial class MoveTowardsPlayer : Sprite2D, IBullet
|
|
{
|
|
[Export(PropertyHint.None, "")]
|
|
private float homing;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float startDelay;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float liveTime = -100f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float speed = 1f;
|
|
|
|
public Vector2 dir;
|
|
|
|
private const float angleFix = -90f;
|
|
|
|
public bool grazed { get; set; }
|
|
|
|
public Node2D node { get; set; }
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public AnimationPlayer anim { get; set; }
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public IBullet.Type type { get; set; }
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public int HP { get; set; } = 1;
|
|
|
|
public BulletGenerator generatedFrom { get; set; }
|
|
|
|
public Action<Node> onShot { get; set; }
|
|
|
|
public override void _Ready()
|
|
{
|
|
if (node == null)
|
|
{
|
|
Node2D node2D = (node = this);
|
|
}
|
|
dir = base.GlobalPosition.DirectionTo(BattleDR.current.soul.GlobalPosition);
|
|
LookAt(BattleDR.current.soul.GlobalPosition);
|
|
base.RotationDegrees += -90f;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (startDelay > 0f)
|
|
{
|
|
startDelay -= Main.deltaTime;
|
|
_Ready();
|
|
return;
|
|
}
|
|
if (liveTime > 0f)
|
|
{
|
|
liveTime -= Main.deltaTime;
|
|
}
|
|
else if (liveTime > -50f)
|
|
{
|
|
QueueFree();
|
|
}
|
|
base.GlobalPosition += dir * speed * Main.deltaTime;
|
|
}
|
|
|
|
}
|