Bolt Particle
Adds a bolt particle (So I can make cool electric stuff with it)
This commit is contained in:
1 parent
f02d473e6b
commit
f42cbd3dca
3 files changed
+91
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
@@ -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<Texture2D>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user