83 lines
1.7 KiB
C#
83 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Bullets/WardenGun.cs")]
|
|
public partial class WardenGun : Sprite2D
|
|
{
|
|
public partial class Bullet
|
|
{
|
|
public Node2D obj;
|
|
|
|
public Vector2 direction;
|
|
}
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D bulletBase;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D point;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AudioStreamPlayer sound;
|
|
|
|
private List<Bullet> bullets = new List<Bullet>();
|
|
|
|
private float cd = 30f;
|
|
|
|
private const float speed = 1f;
|
|
|
|
private bool ready;
|
|
|
|
public override void _Ready()
|
|
{
|
|
base.Modulate = Main.colorClear;
|
|
point = GetChild<Node2D>(0);
|
|
sound = GetChild<AudioStreamPlayer>(1);
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
LookAt(BattleDR.current.soul.GlobalPosition);
|
|
if (cd > 0f)
|
|
{
|
|
cd -= Main.deltaTime;
|
|
}
|
|
if (!ready)
|
|
{
|
|
base.Modulate = Main.colorWhite.Lerp(Main.colorClear, cd / 30f);
|
|
if (cd <= 0f)
|
|
{
|
|
ready = true;
|
|
}
|
|
}
|
|
else if (cd <= 0f)
|
|
{
|
|
cd = Main.RandomRange(30, 60);
|
|
bullets.Add(new Bullet
|
|
{
|
|
obj = (Node2D)bulletBase.Duplicate(),
|
|
direction = point.GlobalPosition.DirectionTo(BattleDR.current.soul.GlobalPosition)
|
|
});
|
|
List<Bullet> list = bullets;
|
|
AddChild(list[list.Count - 1].obj, forceReadableName: false, InternalMode.Disabled);
|
|
List<Bullet> list2 = bullets;
|
|
list2[list2.Count - 1].obj.GlobalPosition = point.GlobalPosition;
|
|
sound.Play();
|
|
}
|
|
for (int i = 0; i < bullets.Count; i++)
|
|
{
|
|
bullets[i].obj.GlobalPosition += bullets[i].direction * Main.deltaTime * 1f;
|
|
}
|
|
}
|
|
|
|
public override void _ExitTree()
|
|
{
|
|
Party.Heal(playSound: false);
|
|
Party.UpdateHUD();
|
|
}
|
|
|
|
}
|