129 lines
2.5 KiB
C#
129 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Bullets/MoveAhead.cs")]
|
|
public partial class MoveAhead : Node2D, IBullet
|
|
{
|
|
private VisibleOnScreenNotifier2D notifier;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AudioStream spawnSound;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Vector2 speed;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public float rotation;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public float rotationLookFix;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public float lifeTime = -100f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public float homing;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private bool local;
|
|
|
|
private bool sound;
|
|
|
|
private Vector2 ogSpd;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public bool grazed { get; set; }
|
|
|
|
public Node2D node { get; set; }
|
|
|
|
public AnimationPlayer anim { get; set; }
|
|
|
|
public BulletGenerator generatedFrom { get; set; }
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public int HP { get; set; } = 1;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public IBullet.Type type { get; set; }
|
|
|
|
public Action<Node> onShot { get; set; }
|
|
|
|
public override void _Ready()
|
|
{
|
|
node = this;
|
|
VisibleOnScreenNotifier2D[] array = Common.FindChildOfType<VisibleOnScreenNotifier2D>(this);
|
|
if (array.Length != 0)
|
|
{
|
|
notifier = array[0];
|
|
}
|
|
}
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
CallDeferred("SetSpd");
|
|
}
|
|
|
|
private void SetSpd()
|
|
{
|
|
ogSpd = speed;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (lifeTime > -15f)
|
|
{
|
|
lifeTime -= Main.deltaTime;
|
|
if (lifeTime < 0f)
|
|
{
|
|
base.Modulate = base.Modulate.Lerp(Main.colorClear, Main.deltaTime * 0.1f);
|
|
}
|
|
}
|
|
else if (lifeTime > -30f)
|
|
{
|
|
QueueFree();
|
|
}
|
|
if (homing > 0f)
|
|
{
|
|
speed = speed.Lerp(base.GlobalPosition.DirectionTo(BattleDR.current.soul.GlobalPosition) * ogSpd.Length(), homing * Main.deltaTime);
|
|
}
|
|
if (!sound && spawnSound != null)
|
|
{
|
|
if (notifier != null)
|
|
{
|
|
if (notifier.IsOnScreen())
|
|
{
|
|
Audio.PlaySound(spawnSound);
|
|
sound = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Audio.PlaySound(spawnSound);
|
|
sound = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
VisibleOnScreenNotifier2D visibleOnScreenNotifier2D = notifier;
|
|
if (visibleOnScreenNotifier2D != null && !visibleOnScreenNotifier2D.IsOnScreen())
|
|
{
|
|
sound = false;
|
|
}
|
|
}
|
|
base.RotationDegrees += rotation;
|
|
if (local)
|
|
{
|
|
base.Position += speed * Main.deltaTime;
|
|
}
|
|
else
|
|
{
|
|
base.GlobalPosition += speed * Main.deltaTime;
|
|
}
|
|
}
|
|
|
|
}
|