Files
CalamityModPublic/Particles/CustomSpark.cs
T
Xyk efe21ddfbf Aetherflux Glowup and Nano Purge Tierswap
Plasma Rifle and Nano Purge swap Places
Aetherflux cannon gets some new visuals and balancing
2024-11-14 12:05:23 -08:00

102 lines
3.7 KiB
C#

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Particles
{
public class CustomSpark : Particle
{
public Color InitialColor;
public bool AffectedByGravity;
public bool FadeIn = false;
public float FadeInScale = 0f;
public bool GlowCenter = false;
public float GlowCenterScale = 1;
public float GlowOpacity = 1;
public string NewTexture;
public float ExtraRotation;
public Vector2 Stretch = new Vector2(0.5f, 1.6f);
public float ShrinkSpeed = 0;
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public bool AltVisual = true;
public override bool UseAdditiveBlend => AltVisual;
public override bool SetLifetime => true;
public override bool UseCustomDraw => true;
public CustomSpark(Vector2 relativePosition, Vector2 velocity, string texture, bool affectedByGravity, int lifetime, float scale, Color color, Vector2 stretch, bool useAddativeBlend = true, bool glowCenter = false, float extraRotation = 0, bool fadeIn = false, bool affectedByLight = false, float shrinkSpeed = 0, float glowCenterScale = 1, float glowOpacity = 1)
{
Position = relativePosition;
Velocity = velocity;
NewTexture = texture;
ExtraRotation = extraRotation;
AffectedByGravity = affectedByGravity;
AffectedByLight = affectedByLight;
Scale = scale;
Stretch = stretch;
FadeInScale = scale;
Lifetime = lifetime;
Color = InitialColor = color;
ShrinkSpeed = shrinkSpeed;
AltVisual = useAddativeBlend;
GlowCenter = glowCenter;
GlowCenterScale = glowCenterScale;
GlowOpacity = glowOpacity;
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 + ExtraRotation;
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<Texture2D>(NewTexture).Value;
Color col = Color;
if (AffectedByLight)
{
col = Lighting.GetColor((Position / 16).ToPoint()).MultiplyRGB(Color);
}
spriteBatch.Draw(texture, Position - Main.screenPosition, null, col, Rotation, texture.Size() * 0.5f, scale, 0, 0f);
if (GlowCenter)
spriteBatch.Draw(texture, Position - Main.screenPosition, null, Color.Lerp(col, Color.White, 0.8f) * GlowOpacity, Rotation, texture.Size() * 0.5f, scale * 0.8f * GlowCenterScale, 0, 0f);
}
}
}