161 lines
3.6 KiB
C#
161 lines
3.6 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Bullets/FoxDash.cs")]
|
|
public partial class FoxDash : Node2D
|
|
{
|
|
[Export(PropertyHint.None, "")]
|
|
private Blank fox;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float delay = 80f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float speed = 1f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AnimationPlayer anim;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Sprite2D sprite;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private CollisionShape2D shape;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private MoveAhead[] bullets;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Sprite2D[] trail;
|
|
|
|
private bool flip;
|
|
|
|
private bool spawnBullets;
|
|
|
|
private int state;
|
|
|
|
private int currentTrail;
|
|
|
|
private float countdown;
|
|
|
|
private float bulletCD = 3f;
|
|
|
|
private const float x = 120f;
|
|
|
|
private const float limit = 220f;
|
|
|
|
private const float bulletDefault = 3f;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
countdown = delay;
|
|
BattleDR.current.enemies[0].entity.Visible = false;
|
|
spawnBullets = BattleDR.current.enemies[0].HPPercent() < 0.5f || BattleDR.current.enemies[0].spare > 50;
|
|
if (spawnBullets)
|
|
{
|
|
delay = 50f;
|
|
speed *= 1.2f;
|
|
}
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (countdown > 0f)
|
|
{
|
|
if (state != 0)
|
|
{
|
|
shape.SetDeferred("disabled", true);
|
|
anim.Play("Idle");
|
|
state = 0;
|
|
flip = !flip;
|
|
fox.grazed = false;
|
|
sprite.FlipH = flip;
|
|
for (int i = 0; i < trail.Length; i++)
|
|
{
|
|
trail[i].Visible = false;
|
|
}
|
|
}
|
|
countdown -= Main.deltaTime;
|
|
fox.GlobalPosition = fox.GlobalPosition.Lerp(new Vector2((base.GlobalPosition.X + 120f) * (float)((!flip) ? 1 : (-1)), BattleDR.current.soul.GlobalPosition.Y), Main.deltaTime * 0.2f);
|
|
return;
|
|
}
|
|
if (countdown > 0f - delay / 2f)
|
|
{
|
|
if (state == 0)
|
|
{
|
|
Audio.PlaySound("snd_mart_feather_atk1.wav");
|
|
state = 1;
|
|
anim.SpeedScale = 0f;
|
|
}
|
|
countdown -= Main.deltaTime;
|
|
fox.Modulate = Main.colorWhite.Lerp(Main.colorDark, Mathf.Abs(Common.SinOverTime()));
|
|
return;
|
|
}
|
|
if (state == 1)
|
|
{
|
|
Audio.PlaySound("snd_mart_feather_atk1-2.wav");
|
|
state = 2;
|
|
anim.Play("Dash");
|
|
anim.SpeedScale = 1f;
|
|
fox.Modulate = Main.colorWhite;
|
|
shape.SetDeferred("disabled", false);
|
|
}
|
|
if (spawnBullets && bulletCD <= 0f)
|
|
{
|
|
if (Mathf.Abs(fox.GlobalPosition.X - base.GlobalPosition.X) < 50f)
|
|
{
|
|
bulletCD = 3f;
|
|
for (int j = 0; j < 2; j++)
|
|
{
|
|
int num = Main.RandomRange(0, bullets.Length - 1);
|
|
MoveAhead moveAhead;
|
|
AddChild(moveAhead = (MoveAhead)bullets[num].Duplicate(), forceReadableName: false, InternalMode.Disabled);
|
|
moveAhead.speed = ((j == 0) ? (Vector2.Up * 0.5f) : (Vector2.Down * 0.5f));
|
|
moveAhead.GlobalPosition = fox.GlobalPosition;
|
|
moveAhead.ProcessMode = ProcessModeEnum.Inherit;
|
|
}
|
|
}
|
|
}
|
|
else if (bulletCD > 0f)
|
|
{
|
|
bulletCD -= Main.deltaTime;
|
|
}
|
|
if (flip)
|
|
{
|
|
fox.GlobalPosition += Vector2.Right * speed * Main.deltaTime;
|
|
if (fox.GlobalPosition.X > 220f)
|
|
{
|
|
countdown = delay;
|
|
fox.grazed = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
fox.GlobalPosition += Vector2.Left * speed * Main.deltaTime;
|
|
if (fox.GlobalPosition.X < -220f)
|
|
{
|
|
countdown = delay;
|
|
fox.grazed = false;
|
|
}
|
|
}
|
|
trail[currentTrail].GlobalPosition = fox.GlobalPosition;
|
|
trail[currentTrail].Visible = true;
|
|
trail[currentTrail].FlipH = sprite.FlipH;
|
|
currentTrail++;
|
|
if (currentTrail >= trail.Length)
|
|
{
|
|
currentTrail = 0;
|
|
}
|
|
trail[currentTrail].Visible = false;
|
|
}
|
|
|
|
public override void _ExitTree()
|
|
{
|
|
BattleDR.current.enemies[0].entity.Visible = true;
|
|
}
|
|
|
|
}
|