459 lines
14 KiB
C#
459 lines
14 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 class FallBounce : Node2D
|
|
{
|
|
public enum BounceType
|
|
{
|
|
Bounce,
|
|
Stay,
|
|
Roll
|
|
}
|
|
|
|
public class Bullets
|
|
{
|
|
public MoveAhead obj;
|
|
|
|
public bool hit;
|
|
|
|
public BounceType type;
|
|
|
|
public int index;
|
|
}
|
|
|
|
public new class MethodName : Node2D.MethodName
|
|
{
|
|
public new static readonly StringName _EnterTree = "_EnterTree";
|
|
|
|
public new static readonly StringName _Process = "_Process";
|
|
}
|
|
|
|
public new class PropertyName : Node2D.PropertyName
|
|
{
|
|
public static readonly StringName bullets = "bullets";
|
|
|
|
public static readonly StringName bounceType = "bounceType";
|
|
|
|
public static readonly StringName spawnSound = "spawnSound";
|
|
|
|
public static readonly StringName hitSound = "hitSound";
|
|
|
|
public static readonly StringName delay = "delay";
|
|
|
|
public static readonly StringName variance = "variance";
|
|
|
|
public static readonly StringName yOffset = "yOffset";
|
|
|
|
public static readonly StringName bounceDecay = "bounceDecay";
|
|
|
|
public static readonly StringName playerTop = "playerTop";
|
|
|
|
public static readonly StringName startPos = "startPos";
|
|
|
|
public static readonly StringName cd = "cd";
|
|
|
|
public static readonly StringName y = "y";
|
|
}
|
|
|
|
public new class SignalName : Node2D.SignalName
|
|
{
|
|
}
|
|
|
|
[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]);
|
|
}
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal static List<MethodInfo> GetGodotMethodList()
|
|
{
|
|
return new List<MethodInfo>(2)
|
|
{
|
|
new MethodInfo(MethodName._EnterTree, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
|
|
new MethodInfo(MethodName._Process, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, new List<PropertyInfo>
|
|
{
|
|
new PropertyInfo(Variant.Type.Float, "delta", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false)
|
|
}, null)
|
|
};
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
|
|
{
|
|
if (method == MethodName._EnterTree && args.Count == 0)
|
|
{
|
|
_EnterTree();
|
|
ret = default(godot_variant);
|
|
return true;
|
|
}
|
|
if (method == MethodName._Process && args.Count == 1)
|
|
{
|
|
_Process(VariantUtils.ConvertTo<double>(in args[0]));
|
|
ret = default(godot_variant);
|
|
return true;
|
|
}
|
|
return base.InvokeGodotClassMethod(in method, args, out ret);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool HasGodotClassMethod(in godot_string_name method)
|
|
{
|
|
if (method == MethodName._EnterTree)
|
|
{
|
|
return true;
|
|
}
|
|
if (method == MethodName._Process)
|
|
{
|
|
return true;
|
|
}
|
|
return base.HasGodotClassMethod(in method);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool SetGodotClassPropertyValue(in godot_string_name name, in godot_variant value)
|
|
{
|
|
if (name == PropertyName.bullets)
|
|
{
|
|
bullets = VariantUtils.ConvertToSystemArrayOfGodotObject<Node2D>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.bounceType)
|
|
{
|
|
bounceType = VariantUtils.ConvertToArray<BounceType>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.spawnSound)
|
|
{
|
|
spawnSound = VariantUtils.ConvertToSystemArrayOfGodotObject<AudioStream>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.hitSound)
|
|
{
|
|
hitSound = VariantUtils.ConvertToSystemArrayOfGodotObject<AudioStream>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.delay)
|
|
{
|
|
delay = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.variance)
|
|
{
|
|
variance = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.yOffset)
|
|
{
|
|
yOffset = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.bounceDecay)
|
|
{
|
|
bounceDecay = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.playerTop)
|
|
{
|
|
playerTop = VariantUtils.ConvertTo<bool>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.startPos)
|
|
{
|
|
startPos = VariantUtils.ConvertTo<Vector2>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
cd = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.y)
|
|
{
|
|
y = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
return base.SetGodotClassPropertyValue(in name, in value);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool GetGodotClassPropertyValue(in godot_string_name name, out godot_variant value)
|
|
{
|
|
if (name == PropertyName.bullets)
|
|
{
|
|
GodotObject[] array = bullets;
|
|
value = VariantUtils.CreateFromSystemArrayOfGodotObject(array);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.bounceType)
|
|
{
|
|
value = VariantUtils.CreateFromArray(bounceType);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.spawnSound)
|
|
{
|
|
GodotObject[] array = spawnSound;
|
|
value = VariantUtils.CreateFromSystemArrayOfGodotObject(array);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.hitSound)
|
|
{
|
|
GodotObject[] array = hitSound;
|
|
value = VariantUtils.CreateFromSystemArrayOfGodotObject(array);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.delay)
|
|
{
|
|
value = VariantUtils.CreateFrom(in delay);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.variance)
|
|
{
|
|
value = VariantUtils.CreateFrom(in variance);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.yOffset)
|
|
{
|
|
value = VariantUtils.CreateFrom(in yOffset);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.bounceDecay)
|
|
{
|
|
value = VariantUtils.CreateFrom(in bounceDecay);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.playerTop)
|
|
{
|
|
value = VariantUtils.CreateFrom(in playerTop);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.startPos)
|
|
{
|
|
value = VariantUtils.CreateFrom(in startPos);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
value = VariantUtils.CreateFrom(in cd);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.y)
|
|
{
|
|
value = VariantUtils.CreateFrom(in y);
|
|
return true;
|
|
}
|
|
return base.GetGodotClassPropertyValue(in name, out value);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal static List<PropertyInfo> GetGodotPropertyList()
|
|
{
|
|
return new List<PropertyInfo>
|
|
{
|
|
new PropertyInfo(Variant.Type.Array, PropertyName.bullets, PropertyHint.TypeString, "24/34:Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Array, PropertyName.bounceType, PropertyHint.TypeString, "2/2:Bounce,Stay,Roll", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Array, PropertyName.spawnSound, PropertyHint.TypeString, "24/17:AudioStream", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Array, PropertyName.hitSound, PropertyHint.TypeString, "24/17:AudioStream", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.delay, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.variance, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.yOffset, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.bounceDecay, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Bool, PropertyName.playerTop, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Vector2, PropertyName.startPos, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.cd, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.y, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
|
|
};
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void SaveGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.SaveGodotObjectData(info);
|
|
StringName name = PropertyName.bullets;
|
|
GodotObject[] array = bullets;
|
|
info.AddProperty(name, Variant.CreateFrom(array));
|
|
info.AddProperty(PropertyName.bounceType, Variant.CreateFrom(bounceType));
|
|
StringName name2 = PropertyName.spawnSound;
|
|
array = spawnSound;
|
|
info.AddProperty(name2, Variant.CreateFrom(array));
|
|
StringName name3 = PropertyName.hitSound;
|
|
array = hitSound;
|
|
info.AddProperty(name3, Variant.CreateFrom(array));
|
|
info.AddProperty(PropertyName.delay, Variant.From(in delay));
|
|
info.AddProperty(PropertyName.variance, Variant.From(in variance));
|
|
info.AddProperty(PropertyName.yOffset, Variant.From(in yOffset));
|
|
info.AddProperty(PropertyName.bounceDecay, Variant.From(in bounceDecay));
|
|
info.AddProperty(PropertyName.playerTop, Variant.From(in playerTop));
|
|
info.AddProperty(PropertyName.startPos, Variant.From(in startPos));
|
|
info.AddProperty(PropertyName.cd, Variant.From(in cd));
|
|
info.AddProperty(PropertyName.y, Variant.From(in y));
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.RestoreGodotObjectData(info);
|
|
if (info.TryGetProperty(PropertyName.bullets, out var value))
|
|
{
|
|
bullets = value.AsGodotObjectArray<Node2D>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.bounceType, out var value2))
|
|
{
|
|
bounceType = value2.AsGodotArray<BounceType>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.spawnSound, out var value3))
|
|
{
|
|
spawnSound = value3.AsGodotObjectArray<AudioStream>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.hitSound, out var value4))
|
|
{
|
|
hitSound = value4.AsGodotObjectArray<AudioStream>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.delay, out var value5))
|
|
{
|
|
delay = value5.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.variance, out var value6))
|
|
{
|
|
variance = value6.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.yOffset, out var value7))
|
|
{
|
|
yOffset = value7.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.bounceDecay, out var value8))
|
|
{
|
|
bounceDecay = value8.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.playerTop, out var value9))
|
|
{
|
|
playerTop = value9.As<bool>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.startPos, out var value10))
|
|
{
|
|
startPos = value10.As<Vector2>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.cd, out var value11))
|
|
{
|
|
cd = value11.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.y, out var value12))
|
|
{
|
|
y = value12.As<float>();
|
|
}
|
|
}
|
|
}
|