Files
CalamityModPublic/Particles/GlowSparkParticle.cs
T

65 lines
2.3 KiB
C#

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Particles
{
public class GlowSparkParticle : Particle
{
public Color InitialColor;
public bool AffectedByGravity;
public bool QuickShrink;
public bool Glowing;
public Vector2 Squash = new Vector2(0.5f, 1.6f);
public override bool SetLifetime => true;
public override bool UseCustomDraw => true;
public override bool UseAdditiveBlend => true;
public override string Texture => "CalamityMod/Particles/GlowSpark";
public GlowSparkParticle(Vector2 relativePosition, Vector2 velocity, bool affectedByGravity, int lifetime, float scale, Color color, Vector2 squash, bool quickShrink = false, bool glow = true)
{
Position = relativePosition;
Velocity = velocity;
AffectedByGravity = affectedByGravity;
Scale = scale;
Lifetime = lifetime;
Color = InitialColor = color;
Squash = squash;
QuickShrink = quickShrink;
Glowing = glow;
Rotation = Velocity.ToRotation() + MathHelper.PiOver2;
}
public override void Update()
{
Scale *= 0.95f;
Color = Color.Lerp(InitialColor, Color.Transparent, (float)Math.Pow(LifetimeCompletion, 3D));
Velocity *= 0.95f;
if (QuickShrink)
{
Squash.X *= 0.8f;
Squash.Y *= 1.25f;
}
if (Velocity.Length() < 12f && AffectedByGravity)
{
Velocity.X *= 0.94f;
Velocity.Y += 0.25f;
}
Rotation = Velocity.ToRotation() + MathHelper.PiOver2;
}
public override void CustomDraw(SpriteBatch spriteBatch)
{
Vector2 scale = Squash * Scale;
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
spriteBatch.Draw(texture, Position - Main.screenPosition, null, Color, Rotation, texture.Size() * 0.5f, scale, 0, 0f);
if (Glowing)
spriteBatch.Draw(texture, Position - Main.screenPosition, null, Color.White, Rotation, texture.Size() * 0.5f, scale * new Vector2(0.45f, 1f), 0, 0f);
}
}
}