using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using Terraria; using Terraria.ModLoader; namespace CalamityMod.Particles { public class SquareAshParticle : Particle { public Color InitialColor; public override bool SetLifetime => true; public override bool UseCustomDraw => true; public override bool UseAdditiveBlend => false; public override string Texture => "CalamityMod/Particles/Square"; public SquareAshParticle(Vector2 relativePosition, Vector2 velocity, int lifetime, float scale, Color color) { Position = relativePosition; Velocity = velocity; Scale = scale; Lifetime = lifetime; Color = InitialColor = color; } public override void Update() { // Shrink to nothing near end of lifetime if (Time > Lifetime - 60) { Scale *= 0.95f; } Color = Color.Lerp(InitialColor, Color.Transparent, (float)Math.Pow(LifetimeCompletion, 3D)); Rotation += Velocity.X > 0 ? 0.8f : -0.8f; } public override void CustomDraw(SpriteBatch spriteBatch) { Vector2 scale = new Vector2(0.8f, 1.2f) * Scale; Texture2D texture = ModContent.Request(Texture).Value; spriteBatch.Draw(texture, Position - Main.screenPosition, null, Color, Rotation, texture.Size() * 0.5f, scale, 0, 0f); } } }