diff --git a/Dusts/PumplerDust.cs b/Dusts/PumplerDust.cs
index a83524b6cc..ea6b3fc929 100644
--- a/Dusts/PumplerDust.cs
+++ b/Dusts/PumplerDust.cs
@@ -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)
diff --git a/Particles/BaseParticleSet.cs b/Particles/BaseParticleSet.cs
index a172223884..ba60271776 100644
--- a/Particles/BaseParticleSet.cs
+++ b/Particles/BaseParticleSet.cs
@@ -5,21 +5,38 @@ using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ID;
+using Terraria.ModLoader;
namespace CalamityMod.Particles
{
+ ///
+ /// 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
+ ///
public abstract class BaseParticleSet
{
public int LocalTimer { get; internal set; }
public int SetLifetime { get; internal set; }
+ ///
+ /// The amount of frames it takes for a new particle to be spawned in the set.
+ ///
public int ParticleSpawnRate;
+ ///
+ /// The particles in the set
+ ///
public List Particles = new List();
+ ///
+ /// 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.
+ ///
public abstract int ParticleLifetime { get; }
- public abstract void UpdateBehavior(Particle particle);
+ ///
+ /// The particle spawned by the set
+ ///
+ ///
public abstract Particle SpawnParticle();
- public abstract Color DetermineParticleColor(float lifetimeCompletion);
- public abstract Texture2D ParticleTexture { get; }
- public virtual int ParticleFrameVariants => 1;
public virtual Func 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);
}
}
}
diff --git a/Particles/EnchantedParticle.cs b/Particles/EnchantedParticle.cs
new file mode 100644
index 0000000000..8d03ea184b
--- /dev/null
+++ b/Particles/EnchantedParticle.cs
@@ -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;
+ }
+ }
+}
diff --git a/Particles/EnchantedParticleSet.cs b/Particles/EnchantedParticleSet.cs
index 4feb625237..82ef4e3c9a 100644
--- a/Particles/EnchantedParticleSet.cs
+++ b/Particles/EnchantedParticleSet.cs
@@ -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);
}
}
\ No newline at end of file
diff --git a/ExtraTextures/Particles/Fire.png b/Particles/Fire.png
similarity index 100%
rename from ExtraTextures/Particles/Fire.png
rename to Particles/Fire.png
diff --git a/Particles/FireParticle.cs b/Particles/FireParticle.cs
new file mode 100644
index 0000000000..5aa8e54ccd
--- /dev/null
+++ b/Particles/FireParticle.cs
@@ -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;
+ }
+ }
+}
diff --git a/Particles/FireParticleSet.cs b/Particles/FireParticleSet.cs
index fd362b1a76..4dbfe1275b 100644
--- a/Particles/FireParticleSet.cs
+++ b/Particles/FireParticleSet.cs
@@ -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);
}
}
\ No newline at end of file
diff --git a/Particles/GeneralParticleHandler.cs b/Particles/GeneralParticleHandler.cs
index aee0bff66a..fb18af3fb1 100644
--- a/Particles/GeneralParticleHandler.cs
+++ b/Particles/GeneralParticleHandler.cs
@@ -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();
}
}
diff --git a/Particles/GenericSparkle.cs b/Particles/GenericSparkle.cs
new file mode 100644
index 0000000000..a83c687b6d
--- /dev/null
+++ b/Particles/GenericSparkle.cs
@@ -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);
+ }
+
+
+ }
+}
diff --git a/ExtraTextures/Particles/Light.png b/Particles/Light.png
similarity index 100%
rename from ExtraTextures/Particles/Light.png
rename to Particles/Light.png
diff --git a/ExtraTextures/ThanatosVentParticle.png b/Particles/MediumSmoke.png
similarity index 100%
rename from ExtraTextures/ThanatosVentParticle.png
rename to Particles/MediumSmoke.png
diff --git a/Particles/Particle.cs b/Particles/Particle.cs
index 9655c90f7d..70bfe50976 100644
--- a/Particles/Particle.cs
+++ b/Particles/Particle.cs
@@ -17,14 +17,17 @@ namespace CalamityMod.Particles
/// The amount of frames this particle has existed for. You shouldn't have to touch this manually.
///
public int Time;
+
///
- /// 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
///
- public int Lifetime;
+ public virtual bool SetLifetime => false;
+ ///
+ /// The maximum amount of frames a particle may stay alive if Particle.SetLifeTime is set to true
+ ///
+ public int Lifetime = 0;
- public int FrameVariants = 1;
- public int Variant = 0;
+ public float LifetimeCompletion => Lifetime != 0 ? Time / Lifetime : 0;
///
/// 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 => "";
///
/// Set this to true to disable default particle drawing, thus calling Particle.CustomDraw() instead.
@@ -67,22 +71,5 @@ namespace CalamityMod.Particles
///
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;
- }
}
}
\ No newline at end of file
diff --git a/Dusts/SmallSmoke.png b/Particles/SmallSmoke.png
similarity index 100%
rename from Dusts/SmallSmoke.png
rename to Particles/SmallSmoke.png
diff --git a/Particles/ThanatosSmokeParticle.cs b/Particles/ThanatosSmokeParticle.cs
new file mode 100644
index 0000000000..cd039bb100
--- /dev/null
+++ b/Particles/ThanatosSmokeParticle.cs
@@ -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;
+ }
+
+ }
+}
diff --git a/Particles/ThanatosSmokeParticleSet.cs b/Particles/ThanatosSmokeParticleSet.cs
index abff9d70c8..3037de7bb2 100644
--- a/Particles/ThanatosSmokeParticleSet.cs
+++ b/Particles/ThanatosSmokeParticleSet.cs
@@ -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);
}
}
\ No newline at end of file