using System.Collections.Generic; using System.ComponentModel; using Godot; using Godot.Bridge; using Godot.NativeInterop; [ScriptPath("res://Scripts/Bullets/BearingJump.cs")] public partial class BearingJump : Node2D { [Export(PropertyHint.None, "")] private Node2D bullet; [Export(PropertyHint.None, "")] private AudioStream jump; [Export(PropertyHint.None, "")] private AudioStream charge; [Export(PropertyHint.None, "")] private AudioStream impact; [Export(PropertyHint.None, "")] private float waitDelay = 30f; [Export(PropertyHint.None, "")] private float fallTime = 15f; [Export(PropertyHint.None, "")] private float bulletSpeedMod = 0.65f; private Entity entity; private Vector2 sp; private Vector2 bp; private int state; private float cd; private float wait; private bool bul; private Vector2[] pos; private List bullets = new List(); private readonly StringName jumpAnim = "Fall"; private readonly StringName punchAnim = "Land"; private readonly StringName chargeAnim = "Charge"; private readonly Color glow = new Color(2.5f, 2.5f, 2.5f); private readonly Vector2[] bspd = new Vector2[4] { new Vector2(0.7f, 1.7f), new Vector2(-0.7f, 1.7f), new Vector2(0.7f, -0.7f), new Vector2(-0.7f, -0.7f) }; private readonly Vector2 grav = new Vector2(0f, -0.02f); public override void _EnterTree() { entity = BattleDR.current.enemies[0].entity; entity.Modulate = Main.colorWhite; sp = entity.GlobalPosition; entity.doTrail = true; bp = BattleDR.current.activeBoard.GlobalPosition; entity.Reparent(this); entity.CollisionLayer = 4u; if (BattleDR.current.enemies[0].HPPercent() <= 0.5f || BattleDR.current.enemies[0].spare >= 50) { wait = fallTime * 2f; waitDelay = Mathf.RoundToInt(waitDelay * 0.75f); } else { wait = fallTime * 3f; } } public override void _ExitTree() { entity.doTrail = false; entity.Modulate = Main.colorWhite; entity.Reparent(BattleDR.current); entity.shake = 0f; entity.CollisionLayer = 1u; } public override void _Process(double delta) { for (int num = bullets.Count - 1; num >= 0; num--) { if (!GodotObject.IsInstanceValid(bullets[num])) { bullets.RemoveAt(num); } else { bullets[num].speed += grav * Main.deltaTime; } } switch (state) { case 0: if (pos == null) { pos = new Vector2[3] { entity.GlobalPosition, new Vector2(BattleDR.current.soul.GlobalPosition.X, bp.Y - 55f), Vector2.Zero }; pos[2] = new Vector2(Mathf.Lerp(pos[0].X, pos[1].X, 0.5f), bp.Y - 80f); Audio.PlaySound(jump); entity.anim.Play(jumpAnim); } if (cd < 40f) { cd += Main.deltaTime; entity.GlobalPosition = Common.Beizier(pos[0], pos[2], pos[1], cd / 40f); break; } state = 1; cd = 0f; pos = new Vector2[2] { entity.GlobalPosition, new Vector2(pos[1].X, bp.Y + BattleDR.current.activeBoard.boardSize.Y / 2f) }; entity.Shake(waitDelay, 1f); entity.anim.Play(chargeAnim); Audio.PlaySound(charge); break; case 1: if (cd < waitDelay) { cd += Main.deltaTime; entity.Modulate = ((Common.SinOverTime(1.25f) > 0f) ? Main.colorWhite : glow); break; } entity.Modulate = Main.colorWhite; state = 2; cd = 0f; entity.anim.Play(punchAnim); break; case 2: cd += Main.deltaTime; if (cd <= fallTime) { entity.GlobalPosition = pos[0].Lerp(pos[1], cd / fallTime); } else if (cd < wait) { if (bul) { break; } entity.GlobalPosition = pos[1]; Audio.PlaySound(impact); CameraController.Shake(15f, 2f); entity.Shake(10f, 2f); bul = true; if (!(BattleDR.current.activeBoard.timer > 10f)) { break; } for (int i = 0; i < 4; i++) { MoveAhead moveAhead = (MoveAhead)BattleDR.NewBullet(in bullet, entity.GlobalPosition + Vector2.Up * 32f, this); moveAhead.speed = bspd[i] * bulletSpeedMod; bullets.Add(moveAhead); moveAhead.RotationDegrees = Main.RandomRange(0, 360); if (bspd[i].X > 0f) { moveAhead.rotation *= -1f; } } } else { bul = false; cd = 0f; state = 0; pos = null; } break; } } }