diff --git a/Particles/Bolt.png b/Particles/Bolt.png new file mode 100644 index 0000000000..cec6f3d327 Binary files /dev/null and b/Particles/Bolt.png differ diff --git a/Particles/Bolt2.png b/Particles/Bolt2.png new file mode 100644 index 0000000000..b17c8ed67b Binary files /dev/null and b/Particles/Bolt2.png differ diff --git a/Particles/BoltParticle.cs b/Particles/BoltParticle.cs new file mode 100644 index 0000000000..a83ee88aea --- /dev/null +++ b/Particles/BoltParticle.cs @@ -0,0 +1,91 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class BoltParticle : Particle + { + public Color InitialColor; + public bool AffectedByGravity; + public bool FadeIn = false; + public float FadeInScale = 0f; + public bool GlowCenter = false; + public Vector2 Stretch = new Vector2(0.5f, 1.6f); + public float ShrinkSpeed = 0; + public bool Fliped = false; + + public override int FrameVariants => 3; + public override string Texture => "CalamityMod/Particles/Bolt2"; + public override bool UseAdditiveBlend => true; + public override bool SetLifetime => true; + public override bool UseCustomDraw => true; + + public BoltParticle(Vector2 relativePosition, Vector2 velocity, bool affectedByGravity, int lifetime, float scale, Color color, Vector2 stretch, bool glowCenter = false, bool fadeIn = false, float shrinkSpeed = 0) + { + Position = relativePosition; + Velocity = velocity; + AffectedByGravity = affectedByGravity; + Scale = scale; + Stretch = stretch; + FadeInScale = scale; + Lifetime = lifetime; + Color = InitialColor = color; + ShrinkSpeed = shrinkSpeed; + GlowCenter = glowCenter; + Variant = Main.rand.Next(3); + Fliped = Main.rand.NextBool(); + + FadeIn = fadeIn; + + if (FadeIn) + Scale = 0f; + } + + public override void Update() + { + if (!FadeIn) + { + Scale *= 0.95f; + Color = Color.Lerp(InitialColor, Color.Transparent, (float)Math.Pow(LifetimeCompletion, 3D)); + } + else + { + if ((float)Time / (float)Lifetime < 0.5f) + { + Scale = MathHelper.Lerp(Scale, FadeInScale, 0.2f); + } + else + { + Scale = MathHelper.Lerp(Scale, FadeInScale, -0.21f); + } + } + Velocity *= 0.95f; + if (Velocity.Length() < 12f && AffectedByGravity) + { + Velocity.X *= 0.94f; + Velocity.Y += 0.25f; + } + Rotation = Velocity.ToRotation() + MathHelper.PiOver2; + + Stretch.X *= (1 - 0.2f * ShrinkSpeed); + Stretch.Y *= (1 + 0.2f * ShrinkSpeed); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Vector2 scale = Stretch * Scale; + Texture2D texture = ModContent.Request(Texture).Value; + Rectangle frame = texture.Frame(1, 3, 0, Variant); + Vector2 origin = frame.Size() * 0.5f; + + Color col = Color; + + spriteBatch.Draw(texture, Position - Main.screenPosition, frame, col, Rotation, origin, scale, Fliped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0f); + if (GlowCenter) + spriteBatch.Draw(texture, Position - Main.screenPosition, frame, Color.Lerp(col, Color.White, 0.8f), Rotation, origin, scale * 0.8f, Fliped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0f); + } + } +}