496 lines
14 KiB
C#
496 lines
14 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Bullets/PenniltonSpin.cs")]
|
|
public class PenniltonSpin : Node2D
|
|
{
|
|
public new class MethodName : Node2D.MethodName
|
|
{
|
|
public new static readonly StringName _Ready = "_Ready";
|
|
|
|
public new static readonly StringName _Process = "_Process";
|
|
}
|
|
|
|
public new class PropertyName : Node2D.PropertyName
|
|
{
|
|
public static readonly StringName obj = "obj";
|
|
|
|
public static readonly StringName warning = "warning";
|
|
|
|
public static readonly StringName col = "col";
|
|
|
|
public static readonly StringName appear = "appear";
|
|
|
|
public static readonly StringName spin = "spin";
|
|
|
|
public static readonly StringName coinSound = "coinSound";
|
|
|
|
public static readonly StringName coinPrefab = "coinPrefab";
|
|
|
|
public static readonly StringName grow = "grow";
|
|
|
|
public static readonly StringName spd = "spd";
|
|
|
|
public static readonly StringName cd = "cd";
|
|
|
|
public static readonly StringName midTime = "midTime";
|
|
|
|
public static readonly StringName coinCD = "coinCD";
|
|
|
|
public static readonly StringName set = "set";
|
|
|
|
public static readonly StringName flip = "flip";
|
|
|
|
public static readonly StringName weak = "weak";
|
|
}
|
|
|
|
public new class SignalName : Node2D.SignalName
|
|
{
|
|
}
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Blank obj;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node warning;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Area2D col;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AudioStream appear;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AudioStream spin;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AudioStream coinSound;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private PackedScene coinPrefab;
|
|
|
|
private float grow;
|
|
|
|
private float spd;
|
|
|
|
private float cd = 15f;
|
|
|
|
private float midTime;
|
|
|
|
private float coinCD;
|
|
|
|
private bool set;
|
|
|
|
private bool flip;
|
|
|
|
private bool weak;
|
|
|
|
private Coroutine flipping;
|
|
|
|
private List<PenniltonSimple.Coins> coins = new List<PenniltonSimple.Coins>();
|
|
|
|
public override void _Ready()
|
|
{
|
|
obj.Modulate = Main.colorClear;
|
|
midTime = BattleDR.current.activeBoard.timer / 2f;
|
|
weak = BattleDR.current.enemies[0].GetProgress() >= 0.5f;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (GodotObject.IsInstanceValid(warning))
|
|
{
|
|
return;
|
|
}
|
|
PenniltonSimple.PennyCoinLogic(this, in coins, coinSound, 80f, -1f, 0.9f, 20f);
|
|
if (weak)
|
|
{
|
|
coinCD -= Main.deltaTime;
|
|
if (coinCD <= 0f && coins.Count < 3)
|
|
{
|
|
coinCD = Main.RandomRange(40, 80);
|
|
IBullet bullet = (IBullet)BattleDR.NewBullet(in coinPrefab, new Vector2(200f, (coins.Count == 0) ? BattleDR.current.soul.GlobalPosition.Y : (base.GlobalPosition.Y + Main.RandomRange(0f - BattleDR.current.activeBoard.boardSize.Y, BattleDR.current.activeBoard.boardSize.Y) * 0.4f)));
|
|
bullet.type = IBullet.Type.Yellow;
|
|
bullet.node.Modulate = Main.colorYellow;
|
|
coins.Add(new PenniltonSimple.Coins
|
|
{
|
|
obj = bullet.node
|
|
});
|
|
Audio.PlaySound(coinSound);
|
|
}
|
|
}
|
|
if (grow < 30f)
|
|
{
|
|
grow += Main.deltaTime;
|
|
obj.Modulate = Main.colorClear.Lerp(Main.colorWhite, grow / 30f);
|
|
return;
|
|
}
|
|
if (!set)
|
|
{
|
|
col.CollisionLayer = 4u;
|
|
}
|
|
if (!flip && weak && flipping == null && BattleDR.current.activeBoard.timer < midTime)
|
|
{
|
|
flipping = Coroutine.Start(Flip());
|
|
}
|
|
if (flip)
|
|
{
|
|
if (spd > -1.25f)
|
|
{
|
|
spd -= Main.deltaTime * 0.05f;
|
|
}
|
|
}
|
|
else if (spd < 1.25f)
|
|
{
|
|
spd += Main.deltaTime * 0.05f;
|
|
}
|
|
obj.RotationDegrees += spd * Main.deltaTime;
|
|
if (cd <= 0f)
|
|
{
|
|
Audio.PlaySound(spin);
|
|
obj.grazed = false;
|
|
cd = 120f;
|
|
}
|
|
else
|
|
{
|
|
cd -= Main.deltaTime;
|
|
}
|
|
}
|
|
|
|
private IEnumerator Flip()
|
|
{
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
Audio.PlaySound("snd_bombfall.wav");
|
|
obj.Modulate = Main.colorDark;
|
|
for (float a = 0f; a < 10f; a += Main.deltaTime)
|
|
{
|
|
yield return null;
|
|
}
|
|
obj.Modulate = Main.colorWhite;
|
|
}
|
|
flip = true;
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal static List<MethodInfo> GetGodotMethodList()
|
|
{
|
|
return new List<MethodInfo>(2)
|
|
{
|
|
new MethodInfo(MethodName._Ready, 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._Ready && args.Count == 0)
|
|
{
|
|
_Ready();
|
|
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._Ready)
|
|
{
|
|
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.obj)
|
|
{
|
|
obj = VariantUtils.ConvertTo<Blank>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.warning)
|
|
{
|
|
warning = VariantUtils.ConvertTo<Node>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.col)
|
|
{
|
|
col = VariantUtils.ConvertTo<Area2D>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.appear)
|
|
{
|
|
appear = VariantUtils.ConvertTo<AudioStream>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.spin)
|
|
{
|
|
spin = VariantUtils.ConvertTo<AudioStream>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.coinSound)
|
|
{
|
|
coinSound = VariantUtils.ConvertTo<AudioStream>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.coinPrefab)
|
|
{
|
|
coinPrefab = VariantUtils.ConvertTo<PackedScene>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.grow)
|
|
{
|
|
grow = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.spd)
|
|
{
|
|
spd = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
cd = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.midTime)
|
|
{
|
|
midTime = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.coinCD)
|
|
{
|
|
coinCD = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.set)
|
|
{
|
|
set = VariantUtils.ConvertTo<bool>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.flip)
|
|
{
|
|
flip = VariantUtils.ConvertTo<bool>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.weak)
|
|
{
|
|
weak = VariantUtils.ConvertTo<bool>(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.obj)
|
|
{
|
|
value = VariantUtils.CreateFrom(in obj);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.warning)
|
|
{
|
|
value = VariantUtils.CreateFrom(in warning);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.col)
|
|
{
|
|
value = VariantUtils.CreateFrom(in col);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.appear)
|
|
{
|
|
value = VariantUtils.CreateFrom(in appear);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.spin)
|
|
{
|
|
value = VariantUtils.CreateFrom(in spin);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.coinSound)
|
|
{
|
|
value = VariantUtils.CreateFrom(in coinSound);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.coinPrefab)
|
|
{
|
|
value = VariantUtils.CreateFrom(in coinPrefab);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.grow)
|
|
{
|
|
value = VariantUtils.CreateFrom(in grow);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.spd)
|
|
{
|
|
value = VariantUtils.CreateFrom(in spd);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
value = VariantUtils.CreateFrom(in cd);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.midTime)
|
|
{
|
|
value = VariantUtils.CreateFrom(in midTime);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.coinCD)
|
|
{
|
|
value = VariantUtils.CreateFrom(in coinCD);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.set)
|
|
{
|
|
value = VariantUtils.CreateFrom(in set);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.flip)
|
|
{
|
|
value = VariantUtils.CreateFrom(in flip);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.weak)
|
|
{
|
|
value = VariantUtils.CreateFrom(in weak);
|
|
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.Object, PropertyName.obj, PropertyHint.NodeType, "Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.warning, PropertyHint.NodeType, "Node", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.col, PropertyHint.NodeType, "Area2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.appear, PropertyHint.ResourceType, "AudioStream", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.spin, PropertyHint.ResourceType, "AudioStream", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.coinSound, PropertyHint.ResourceType, "AudioStream", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.coinPrefab, PropertyHint.ResourceType, "PackedScene", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.grow, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.spd, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.cd, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.midTime, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.coinCD, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Bool, PropertyName.set, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Bool, PropertyName.flip, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Bool, PropertyName.weak, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
|
|
};
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void SaveGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.SaveGodotObjectData(info);
|
|
info.AddProperty(PropertyName.obj, Variant.From(in obj));
|
|
info.AddProperty(PropertyName.warning, Variant.From(in warning));
|
|
info.AddProperty(PropertyName.col, Variant.From(in col));
|
|
info.AddProperty(PropertyName.appear, Variant.From(in appear));
|
|
info.AddProperty(PropertyName.spin, Variant.From(in spin));
|
|
info.AddProperty(PropertyName.coinSound, Variant.From(in coinSound));
|
|
info.AddProperty(PropertyName.coinPrefab, Variant.From(in coinPrefab));
|
|
info.AddProperty(PropertyName.grow, Variant.From(in grow));
|
|
info.AddProperty(PropertyName.spd, Variant.From(in spd));
|
|
info.AddProperty(PropertyName.cd, Variant.From(in cd));
|
|
info.AddProperty(PropertyName.midTime, Variant.From(in midTime));
|
|
info.AddProperty(PropertyName.coinCD, Variant.From(in coinCD));
|
|
info.AddProperty(PropertyName.set, Variant.From(in set));
|
|
info.AddProperty(PropertyName.flip, Variant.From(in flip));
|
|
info.AddProperty(PropertyName.weak, Variant.From(in weak));
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.RestoreGodotObjectData(info);
|
|
if (info.TryGetProperty(PropertyName.obj, out var value))
|
|
{
|
|
obj = value.As<Blank>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.warning, out var value2))
|
|
{
|
|
warning = value2.As<Node>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.col, out var value3))
|
|
{
|
|
col = value3.As<Area2D>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.appear, out var value4))
|
|
{
|
|
appear = value4.As<AudioStream>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.spin, out var value5))
|
|
{
|
|
spin = value5.As<AudioStream>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.coinSound, out var value6))
|
|
{
|
|
coinSound = value6.As<AudioStream>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.coinPrefab, out var value7))
|
|
{
|
|
coinPrefab = value7.As<PackedScene>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.grow, out var value8))
|
|
{
|
|
grow = value8.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.spd, out var value9))
|
|
{
|
|
spd = value9.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.cd, out var value10))
|
|
{
|
|
cd = value10.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.midTime, out var value11))
|
|
{
|
|
midTime = value11.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.coinCD, out var value12))
|
|
{
|
|
coinCD = value12.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.set, out var value13))
|
|
{
|
|
set = value13.As<bool>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.flip, out var value14))
|
|
{
|
|
flip = value14.As<bool>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.weak, out var value15))
|
|
{
|
|
weak = value15.As<bool>();
|
|
}
|
|
}
|
|
}
|