144 lines
3.5 KiB
C#
144 lines
3.5 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.Collections;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Bullets/FallBounce.cs")]
|
|
public partial class FallBounce : Node2D
|
|
{
|
|
public enum BounceType
|
|
{
|
|
Bounce,
|
|
Stay,
|
|
Roll
|
|
}
|
|
|
|
public partial class Bullets
|
|
{
|
|
public MoveAhead obj;
|
|
|
|
public bool hit;
|
|
|
|
public BounceType type;
|
|
|
|
public int index;
|
|
}
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D[] bullets;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Array<BounceType> bounceType;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AudioStream[] spawnSound;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AudioStream[] hitSound;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float delay = 30f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float variance = 10f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float yOffset = 10f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float bounceDecay = 0.05f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private bool playerTop;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Vector2 startPos;
|
|
|
|
private List<Bullets> bulletList = new List<Bullets>();
|
|
|
|
private float cd;
|
|
|
|
private float y;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
y = base.GlobalPosition.Y + BattleDR.current.activeBoard.boardSize.Y / 2f - yOffset;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
for (int num = bulletList.Count - 1; num >= 0; num--)
|
|
{
|
|
if (!GodotObject.IsInstanceValid(bulletList[num].obj))
|
|
{
|
|
bulletList.RemoveAt(num);
|
|
}
|
|
else if (bulletList[num].hit)
|
|
{
|
|
if (bulletList[num].type == BounceType.Bounce)
|
|
{
|
|
bulletList[num].obj.speed += Vector2.Down * Main.deltaTime * bounceDecay;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bulletList[num].obj.Modulate = bulletList[num].obj.Modulate.Lerp(Main.colorWhite, Main.deltaTime * 0.1f);
|
|
if (!bulletList[num].hit && bulletList[num].obj.GlobalPosition.Y > y)
|
|
{
|
|
if (hitSound[bulletList[num].index] != null)
|
|
{
|
|
Audio.PlaySound(hitSound[bulletList[num].index]);
|
|
}
|
|
bulletList[num].hit = true;
|
|
switch (bulletList[num].type)
|
|
{
|
|
case BounceType.Bounce:
|
|
bulletList[num].obj.speed = new Vector2(Main.RandomRange(-1f, 1f), 0f - bulletList[num].obj.speed.Y);
|
|
bulletList[num].obj.rotation = bulletList[num].obj.speed.X * 5f;
|
|
break;
|
|
case BounceType.Roll:
|
|
CameraController.Shake();
|
|
if (Main.RandomRange(0, 100) > 30)
|
|
{
|
|
bulletList[num].obj.speed = new Vector2((!(BattleDR.current.soul.GlobalPosition.X < bulletList[num].obj.GlobalPosition.X)) ? 1 : (-1), 0f);
|
|
}
|
|
else
|
|
{
|
|
bulletList[num].obj.speed = new Vector2((Main.RandomRange(0, 100) <= 50) ? 1 : (-1), 0f);
|
|
}
|
|
bulletList[num].obj.rotation = bulletList[num].obj.speed.X * 5f;
|
|
break;
|
|
case BounceType.Stay:
|
|
bulletList[num].obj.speed = Vector2.Zero;
|
|
bulletList[num].obj.rotation = 0f;
|
|
break;
|
|
}
|
|
bulletList[num].obj.lifeTime = 150f;
|
|
}
|
|
}
|
|
}
|
|
if (cd > 0f)
|
|
{
|
|
cd -= Main.deltaTime;
|
|
return;
|
|
}
|
|
cd = delay + Main.RandomRange(0f - variance, variance);
|
|
int num2 = Main.RandomRange(0, bullets.Length - 1);
|
|
MoveAhead moveAhead = (MoveAhead)BattleDR.NewBullet(in bullets[num2], base.GlobalPosition + startPos + new Vector2(Main.RandomRange(0f - BattleDR.current.activeBoard.boardSize.X, BattleDR.current.activeBoard.boardSize.X) / 2.25f, 0f), this);
|
|
bulletList.Add(new Bullets
|
|
{
|
|
obj = moveAhead,
|
|
type = bounceType[num2],
|
|
index = num2
|
|
});
|
|
moveAhead.Modulate = Main.colorClear;
|
|
if (spawnSound[num2] != null)
|
|
{
|
|
Audio.PlaySound(spawnSound[num2]);
|
|
}
|
|
}
|
|
|
|
}
|