Rewired particleSets
No files matched your search
@@ -4,11 +4,11 @@ using Terraria.ModLoader;
|
||||
|
||||
|
||||
namespace CalamityMod.Dusts {
|
||||
public class PumplerDust : ModDust
|
||||
public class PumplerDust : ModDust //TURN THAT INTO A PARTICLE WHEN I REMEMBER
|
||||
{
|
||||
public override bool Autoload(ref string name, ref string texture)
|
||||
{
|
||||
texture = "CalamityMod/Dusts/SmallSmoke";
|
||||
texture = "CalamityMod/Particles/SmallSmoke";
|
||||
return true;
|
||||
}
|
||||
public override void OnSpawn(Dust dust)
|
||||
|
||||
@@ -5,21 +5,38 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles
|
||||
{
|
||||
/// <summary>
|
||||
/// A set of particles that aren't attached to any particular position in the world, but instead an arbitrary center point defined in the draw function
|
||||
/// The particles in particle sets don't count towards the general particle handler's particle cap since it doesn't process them at all.
|
||||
/// You'll have to manually update and draw these sets.
|
||||
/// TLDR: Groups of particles that work with relative positions instead of world positions and have to be manually updated and drawn
|
||||
/// </summary>
|
||||
public abstract class BaseParticleSet
|
||||
{
|
||||
public int LocalTimer { get; internal set; }
|
||||
public int SetLifetime { get; internal set; }
|
||||
/// <summary>
|
||||
/// The amount of frames it takes for a new particle to be spawned in the set.
|
||||
/// </summary>
|
||||
public int ParticleSpawnRate;
|
||||
/// <summary>
|
||||
/// The particles in the set
|
||||
/// </summary>
|
||||
public List<Particle> Particles = new List<Particle>();
|
||||
/// <summary>
|
||||
/// The lifetime of the particles in the set.
|
||||
/// If the particles spawned don't have this same lifetime set they may get cut off when the set dies.
|
||||
/// </summary>
|
||||
public abstract int ParticleLifetime { get; }
|
||||
public abstract void UpdateBehavior(Particle particle);
|
||||
/// <summary>
|
||||
/// The particle spawned by the set
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract Particle SpawnParticle();
|
||||
public abstract Color DetermineParticleColor(float lifetimeCompletion);
|
||||
public abstract Texture2D ParticleTexture { get; }
|
||||
public virtual int ParticleFrameVariants => 1;
|
||||
public virtual Func<Particle, int> OrderFunction { get; } = null;
|
||||
|
||||
public BaseParticleSet(int setLifetime, int particleSpawnRate)
|
||||
@@ -34,24 +51,24 @@ namespace CalamityMod.Particles
|
||||
if (Main.netMode == NetmodeID.Server)
|
||||
return;
|
||||
|
||||
//Spawn new particles if time remains
|
||||
bool closeToDeath = LocalTimer >= SetLifetime - ParticleLifetime && SetLifetime > 0;
|
||||
if (LocalTimer % ParticleSpawnRate == ParticleSpawnRate - 1 && !closeToDeath)
|
||||
{
|
||||
Particle particle = SpawnParticle();
|
||||
particle.Lifetime = ParticleLifetime;
|
||||
particle.Variant = Main.rand.Next(ParticleFrameVariants);
|
||||
Particles.Add(particle);
|
||||
}
|
||||
|
||||
// Update and increment the time of all particles.
|
||||
for (int i = 0; i < Particles.Count; i++)
|
||||
// Update and increment the time of all particles, alongside modifying their offset based on their velocity.
|
||||
foreach(Particle particle in Particles)
|
||||
{
|
||||
Particles[i].Time++;
|
||||
UpdateBehavior(Particles[i]);
|
||||
particle.RelativeOffset += particle.Velocity;
|
||||
particle.Time++;
|
||||
particle.Update();
|
||||
}
|
||||
|
||||
// Clear all expired particles.
|
||||
Particles.RemoveAll(particle => particle.Time >= particle.Lifetime);
|
||||
Particles.RemoveAll(particle => particle.Time >= particle.Lifetime && particle.SetLifetime);
|
||||
LocalTimer++;
|
||||
}
|
||||
|
||||
@@ -70,11 +87,13 @@ namespace CalamityMod.Particles
|
||||
particle.CustomDraw(Main.spriteBatch);
|
||||
else
|
||||
{
|
||||
Vector2 drawPosition = basePosition - Main.screenPosition + particle.RelativeOffset;
|
||||
Color particleColor = DetermineParticleColor(particle.Time / (float)particle.Lifetime);
|
||||
Rectangle frame = ParticleTexture.Frame(1, ParticleFrameVariants, 0, particle.Variant);
|
||||
var tex = ModContent.GetTexture(particle.Texture);
|
||||
|
||||
Main.spriteBatch.Draw(ParticleTexture, drawPosition, frame, particleColor, 0f, frame.Size() * 0.5f, particle.Scale, SpriteEffects.None, 0f);
|
||||
Vector2 drawPosition = basePosition - Main.screenPosition + particle.RelativeOffset;
|
||||
Color particleColor = particle.Color;
|
||||
Rectangle frame = tex.Frame(1, particle.FrameVariants, 0, particle.Variant);
|
||||
|
||||
Main.spriteBatch.Draw(tex, drawPosition, frame, particle.Color, 0f, frame.Size() * 0.5f, particle.Scale, SpriteEffects.None, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles
|
||||
{
|
||||
public class EnchantedParticle : Particle
|
||||
{
|
||||
public float RelativePower;
|
||||
public override bool SetLifetime => true;
|
||||
|
||||
public float InterpolationSpeed;
|
||||
public float EdgeOffset;
|
||||
public Color EdgeColor;
|
||||
public Color CenterColor;
|
||||
|
||||
public override string Texture => "CalamityMod/Particles/Light";
|
||||
|
||||
public EnchantedParticle(Vector2 relativePosition, int lifetime, float scale, Color edgeColor, Color centerColor, float interpolationSpeed, float edgeOffset)
|
||||
{
|
||||
RelativeOffset = relativePosition;
|
||||
Velocity = Vector2.Zero;
|
||||
Scale = scale;
|
||||
Variant = Main.rand.Next(3);
|
||||
Lifetime = lifetime;
|
||||
EdgeColor = edgeColor;
|
||||
CenterColor = centerColor;
|
||||
InterpolationSpeed = interpolationSpeed;
|
||||
EdgeOffset = edgeOffset;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
float distanceToCenter = RelativeOffset.Length();
|
||||
Scale = MathHelper.SmoothStep(0.05f, 0.125f, Utils.InverseLerp(EdgeOffset, 6f, distanceToCenter, true));
|
||||
Scale *= Utils.InverseLerp(Lifetime, Lifetime - 10f, Time, true);
|
||||
|
||||
if (distanceToCenter > 4.5f)
|
||||
RelativeOffset = Vector2.Lerp(RelativeOffset, Vector2.Zero, InterpolationSpeed);
|
||||
|
||||
Color = Color.Lerp(EdgeColor, CenterColor, Utils.InverseLerp(0f, 0.67f, LifetimeCompletion, true));
|
||||
Color.A = 50;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ namespace CalamityMod.Particles
|
||||
public Color EdgeColor;
|
||||
public Color CenterColor;
|
||||
public override int ParticleLifetime => 50;
|
||||
public override Texture2D ParticleTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Particles/Light");
|
||||
public ChargingEnergyParticleSet(int setLifetime, int particleSpawnRate, Color edgeColor, Color centerColor, float interpolationSpeed, float edgeOffset) :
|
||||
base(setLifetime, particleSpawnRate)
|
||||
{
|
||||
@@ -22,24 +21,6 @@ namespace CalamityMod.Particles
|
||||
EdgeOffset = edgeOffset;
|
||||
}
|
||||
|
||||
public override void UpdateBehavior(Particle particle)
|
||||
{
|
||||
float distanceToCenter = particle.RelativeOffset.Length();
|
||||
particle.Scale = MathHelper.SmoothStep(0.05f, 0.125f, Utils.InverseLerp(EdgeOffset, 6f, distanceToCenter, true));
|
||||
particle.Scale *= Utils.InverseLerp(ParticleLifetime, ParticleLifetime - 10f, particle.Time, true);
|
||||
|
||||
if (distanceToCenter > 4.5f)
|
||||
particle.RelativeOffset = Vector2.Lerp(particle.RelativeOffset, Vector2.Zero, InterpolationSpeed);
|
||||
}
|
||||
|
||||
public override Color DetermineParticleColor(float lifetimeCompletion)
|
||||
{
|
||||
Color particleColor = Color.Lerp(EdgeColor, CenterColor, Utils.InverseLerp(0f, 0.67f, lifetimeCompletion, true));
|
||||
particleColor.A = 50;
|
||||
|
||||
return particleColor;
|
||||
}
|
||||
|
||||
public override Particle SpawnParticle() => new Particle(ParticleLifetime, Main.rand.NextVector2CircularEdge(1f, 1f) * EdgeOffset, 0.1f);
|
||||
public override Particle SpawnParticle() => new EnchantedParticle(Main.rand.NextVector2CircularEdge(1f, 1f) * EdgeOffset, ParticleLifetime, 0.1f, EdgeColor, CenterColor, InterpolationSpeed, EdgeOffset);
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
@@ -0,0 +1,48 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles
|
||||
{
|
||||
public class FireParticle : Particle
|
||||
{
|
||||
public float RelativePower;
|
||||
public override bool SetLifetime => true;
|
||||
public override int FrameVariants => 3;
|
||||
|
||||
public Color BrightColor;
|
||||
public Color DarkColor;
|
||||
|
||||
public override string Texture => "CalamityMod/Particles/Fire";
|
||||
|
||||
public FireParticle(Vector2 relativePosition, int lifetime, float scale, float relativePower, Color brightColor, Color darkColor)
|
||||
{
|
||||
RelativeOffset = relativePosition;
|
||||
Velocity = Vector2.Zero;
|
||||
Scale = scale;
|
||||
Variant = Main.rand.Next(3);
|
||||
Lifetime = lifetime;
|
||||
RelativePower = relativePower;
|
||||
BrightColor = brightColor;
|
||||
DarkColor = darkColor;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
Scale += RelativePower * 0.01f;
|
||||
RelativeOffset.Y -= RelativePower * 3f;
|
||||
|
||||
Color = Color.Lerp(BrightColor, DarkColor, LifetimeCompletion);
|
||||
Color = Color.Lerp(Color, Color.SaddleBrown, Utils.InverseLerp(0.95f, 0.7f, LifetimeCompletion, true));
|
||||
Color = Color.Lerp(Color, Color.White, Utils.InverseLerp(0.1f, 0.25f, LifetimeCompletion, true) * Utils.InverseLerp(0.4f, 0.25f, LifetimeCompletion, true) * 0.7f);
|
||||
Color *= Utils.InverseLerp(0f, 0.15f, LifetimeCompletion, true) * Utils.InverseLerp(1f, 0.8f, LifetimeCompletion, true) * 0.6f;
|
||||
Color.A = 50;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace CalamityMod.Particles
|
||||
public Color BrightColor;
|
||||
public Color DarkColor;
|
||||
public override int ParticleLifetime => 50;
|
||||
public override Texture2D ParticleTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/Particles/Fire");
|
||||
|
||||
public FireParticleSet(int setLifetime, int particleSpawnRate, Color brightColor, Color darkColor, float spawnAreaCompactness, float relativePower) :
|
||||
base(setLifetime, particleSpawnRate)
|
||||
{
|
||||
@@ -22,23 +22,6 @@ namespace CalamityMod.Particles
|
||||
RelativePower = relativePower;
|
||||
}
|
||||
|
||||
public override void UpdateBehavior(Particle particle)
|
||||
{
|
||||
particle.Scale += RelativePower * 0.01f;
|
||||
particle.RelativeOffset.Y -= RelativePower * 3f;
|
||||
}
|
||||
|
||||
public override Color DetermineParticleColor(float lifetimeCompletion)
|
||||
{
|
||||
Color particleColor = Color.Lerp(BrightColor, DarkColor, lifetimeCompletion);
|
||||
particleColor = Color.Lerp(particleColor, Color.SaddleBrown, Utils.InverseLerp(0.95f, 0.7f, lifetimeCompletion, true));
|
||||
particleColor = Color.Lerp(particleColor, Color.White, Utils.InverseLerp(0.1f, 0.25f, lifetimeCompletion, true) * Utils.InverseLerp(0.4f, 0.25f, lifetimeCompletion, true) * 0.7f);
|
||||
particleColor *= Utils.InverseLerp(0f, 0.15f, lifetimeCompletion, true) * Utils.InverseLerp(1f, 0.8f, lifetimeCompletion, true) * 0.6f;
|
||||
particleColor.A = 50;
|
||||
|
||||
return particleColor;
|
||||
}
|
||||
|
||||
public override Particle SpawnParticle() => new Particle(ParticleLifetime, Main.rand.NextVector2Circular(1f, 1f) * SpawnAreaCompactness, 0.06f);
|
||||
public override Particle SpawnParticle() => new FireParticle(Main.rand.NextVector2Circular(1f, 1f) * SpawnAreaCompactness, ParticleLifetime, 0.06f, RelativePower, BrightColor, DarkColor);
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,10 @@ namespace CalamityMod.Particles
|
||||
particle.Position += particle.Velocity;
|
||||
particle.Time++;
|
||||
particle.Update();
|
||||
|
||||
//Clear out particles whose time is up
|
||||
if (particle.Time >= particle.Lifetime && particle.SetLifetime)
|
||||
particle.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Terraria;
|
||||
|
||||
namespace CalamityMod.Particles
|
||||
{
|
||||
public class GenericSparkle : Particle
|
||||
{
|
||||
public GenericSparkle(Vector2 position, Vector2 velocity, Color color, float scale, int lifeTime, float rotationSpeed = 1f)
|
||||
{
|
||||
Position = position;
|
||||
Velocity = velocity;
|
||||
Color = color;
|
||||
Scale = scale;
|
||||
Lifetime = lifeTime;
|
||||
Rotation = Main.rand.NextFloat(MathHelper.TwoPi);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 408 B After Width: | Height: | Size: 408 B |
@@ -17,14 +17,17 @@ namespace CalamityMod.Particles
|
||||
/// The amount of frames this particle has existed for. You shouldn't have to touch this manually.
|
||||
/// </summary>
|
||||
public int Time;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum amount of frames a particle may stay alive when used in a particle set.
|
||||
/// Keep in mind the general particle handler will not automatically clear particles past their lifetime, nor will it care if the Lifetime isnt set at all.
|
||||
/// Set this to true if you want your particle to automatically get removed when its time reaches its maximum lifetime
|
||||
/// </summary>
|
||||
public int Lifetime;
|
||||
public virtual bool SetLifetime => false;
|
||||
/// <summary>
|
||||
/// The maximum amount of frames a particle may stay alive if Particle.SetLifeTime is set to true
|
||||
/// </summary>
|
||||
public int Lifetime = 0;
|
||||
|
||||
public int FrameVariants = 1;
|
||||
public int Variant = 0;
|
||||
public float LifetimeCompletion => Lifetime != 0 ? Time / Lifetime : 0;
|
||||
|
||||
/// <summary>
|
||||
/// The offset of the particle in relation to the origin of the set it belongs to. This is only used in the context of a Particle Set
|
||||
@@ -36,12 +39,13 @@ namespace CalamityMod.Particles
|
||||
public Vector2 Position;
|
||||
public Vector2 Velocity;
|
||||
|
||||
|
||||
public Vector2 Origin;
|
||||
public Color Color;
|
||||
public float Rotation;
|
||||
public float Scale;
|
||||
|
||||
public virtual int FrameVariants => 1;
|
||||
public int Variant = 0;
|
||||
public virtual string Texture => "";
|
||||
/// <summary>
|
||||
/// Set this to true to disable default particle drawing, thus calling Particle.CustomDraw() instead.
|
||||
@@ -67,22 +71,5 @@ namespace CalamityMod.Particles
|
||||
/// </summary>
|
||||
public void Kill() => GeneralParticleHandler.RemoveParticle(ID);
|
||||
|
||||
public Particle(int lifetime, Vector2 relativeOffset, float scale, int variant = 0)
|
||||
{
|
||||
Time = 0;
|
||||
Lifetime = lifetime;
|
||||
Variant = variant;
|
||||
Scale = scale;
|
||||
RelativeOffset = relativeOffset;
|
||||
}
|
||||
|
||||
public Particle(int lifetime, Vector2 relativeOffset, float scale, int variant = 0)
|
||||
{
|
||||
Time = 0;
|
||||
Lifetime = lifetime;
|
||||
Variant = variant;
|
||||
Scale = scale;
|
||||
RelativeOffset = relativeOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 208 B |
@@ -0,0 +1,48 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Particles
|
||||
{
|
||||
public class ThanatosSmokeParticle : Particle
|
||||
{
|
||||
public float RelativePower;
|
||||
public float BaseMoveRotation;
|
||||
public override bool SetLifetime => true;
|
||||
public override int FrameVariants => 3;
|
||||
|
||||
public override string Texture => "CalamityMod/Particles/MediumSmoke";
|
||||
|
||||
public ThanatosSmokeParticle(Vector2 relativePosition, int lifetime, float scale, float relativePower, float baseMoveRotation)
|
||||
{
|
||||
RelativeOffset = relativePosition;
|
||||
Velocity = Vector2.Zero;
|
||||
Scale = scale;
|
||||
Variant = Main.rand.Next(3);
|
||||
Lifetime = lifetime;
|
||||
RelativePower = relativePower;
|
||||
BaseMoveRotation = baseMoveRotation;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (Scale < 1.25f)
|
||||
Scale += RelativePower * 0.04f;
|
||||
RelativeOffset -= (BaseMoveRotation + Main.rand.NextFloat(-0.18f, 0.18f)).ToRotationVector2() * RelativePower * 4.5f;
|
||||
|
||||
Color = Color.DarkRed;
|
||||
Color = Color.Lerp(Color, new Color(154, 139, 138), (float)Math.Pow(Utils.InverseLerp(0f, 0.57f, LifetimeCompletion, true), 2D) * 0.5f + 0.5f);
|
||||
Color.A = 92;
|
||||
|
||||
float opacity = Utils.InverseLerp(1f, 0.85f, Time / Lifetime, true);
|
||||
Color *= opacity;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,12 @@ namespace CalamityMod.Particles
|
||||
{
|
||||
public class ThanatosSmokeParticleSet : BaseParticleSet
|
||||
{
|
||||
public float SpawnAreaCompactness;
|
||||
public override int ParticleLifetime => 30;
|
||||
public float SpawnAreaCompactness;
|
||||
public float RelativePower;
|
||||
public float BaseMoveRotation;
|
||||
public float MoveRotationOffset;
|
||||
public override int ParticleLifetime => 30;
|
||||
public override int ParticleFrameVariants => 3;
|
||||
public override Texture2D ParticleTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/ThanatosVentParticle");
|
||||
|
||||
public ThanatosSmokeParticleSet(int setLifetime, int particleSpawnRate, float baseMoveRotation, float spawnAreaCompactness, float relativePower) :
|
||||
base(setLifetime, particleSpawnRate)
|
||||
{
|
||||
@@ -24,23 +23,6 @@ namespace CalamityMod.Particles
|
||||
RelativePower = relativePower;
|
||||
}
|
||||
|
||||
public override void UpdateBehavior(Particle particle)
|
||||
{
|
||||
if (particle.Scale < 1.25f)
|
||||
particle.Scale += RelativePower * 0.04f;
|
||||
particle.RelativeOffset -= (BaseMoveRotation + Main.rand.NextFloat(-0.18f, 0.18f)).ToRotationVector2() * RelativePower * 4.5f;
|
||||
}
|
||||
|
||||
public override Color DetermineParticleColor(float lifetimeCompletion)
|
||||
{
|
||||
Color color = Color.DarkRed;
|
||||
color = Color.Lerp(color, new Color(154, 139, 138), (float)Math.Pow(Utils.InverseLerp(0f, 0.57f, lifetimeCompletion, true), 2D) * 0.5f + 0.5f);
|
||||
color.A = 92;
|
||||
|
||||
float opacity = Utils.InverseLerp(1f, 0.85f, lifetimeCompletion, true);
|
||||
return color * opacity;
|
||||
}
|
||||
|
||||
public override Particle SpawnParticle() => new Particle(ParticleLifetime, Main.rand.NextVector2Circular(1f, 1f) * SpawnAreaCompactness, 0.06f, Main.rand.Next(3));
|
||||
public override Particle SpawnParticle() => new ThanatosSmokeParticle(Main.rand.NextVector2Circular(1f, 1f) * SpawnAreaCompactness, ParticleLifetime, 0.06f, RelativePower, BaseMoveRotation);
|
||||
}
|
||||
}
|
||||