Merge pull request #451 from CalamityTeam/expanded-particles

Expanded the current particle system
This commit is contained in:
DominicKarma authored and GitHub committed 2022-01-07 11:17:08 -06:00
commit 36c66282fa
21 files changed
+505 -89

No files matched your search

+8
View File
@@ -30,6 +30,14 @@ namespace CalamityMod
[Tooltip("Enables rendering afterimages for Calamity NPCs, projectiles, etc.\nDisable to improve performance.")]
public bool Afterimages { get; set; }
[Label("Maximum particles")]
[BackgroundColor(192, 54, 64, 192)]
[SliderColor(224, 165, 56, 128)]
[Range(0, 1000)]
[DefaultValue(500)]
[Tooltip("Sets the maximum of particle effects that can exist at once.\nParticles are separate from dust and gores.\nTurn down to improve performance.")]
public int ParticleLimit { get; set; }
[Label("Disable Screenshakes")]
[BackgroundColor(192, 54, 64, 192)]
[DefaultValue(false)]
+14
View File
@@ -207,7 +207,10 @@ namespace CalamityMod
ExoChairSlowdownHotkey = RegisterHotKey("Exo Chair Slow Down", "RightShift");
if (!Main.dedServ)
{
LoadClient();
GeneralParticleHandler.Load();
}
BossRushEvent.Load();
BossHealthBarManager.Load(this);
@@ -396,6 +399,7 @@ namespace CalamityMod
Main.rainTexture = rainOriginal;
Main.manaTexture = manaOriginal;
Main.flyingCarpetTexture = carpetOriginal;
GeneralParticleHandler.Unload();
}
Mount.mounts[Mount.Unicorn].dashSpeed /= CalamityPlayer.UnicornSpeedNerfPower;
Mount.mounts[Mount.Unicorn].runSpeed /= CalamityPlayer.UnicornSpeedNerfPower;
@@ -1598,5 +1602,15 @@ namespace CalamityMod
#region Speedrun Timer Stopper
public override void PreSaveAndQuit() => SpeedrunTimer?.Stop();
#endregion
#region Particles updating
public override void PostUpdateEverything()
{
if (!Main.dedServ)
{
GeneralParticleHandler.Update();
}
}
#endregion
}
}
+2 -2
View File
@@ -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)
+2
View File
@@ -50,6 +50,7 @@ namespace CalamityMod.ILEditing
IL.Terraria.Player.AddBuff += AllowBuffTimeStackingForManaBurn;
IL.Terraria.Main.DoDraw += DrawFusableParticles;
IL.Terraria.Main.DoDraw += DrawAshParticles;
On.Terraria.Main.DrawInterface += DrawGeneralParticles;
On.Terraria.Main.SetDisplayMode += ResetRenderTargetSizes;
IL.Terraria.Main.DrawTiles += DrawCustomLava;
IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw += DrawCustomLava2;
@@ -125,6 +126,7 @@ namespace CalamityMod.ILEditing
IL.Terraria.Player.AddBuff -= AllowBuffTimeStackingForManaBurn;
IL.Terraria.Main.DoDraw -= DrawFusableParticles;
IL.Terraria.Main.DoDraw -= DrawAshParticles;
On.Terraria.Main.DrawInterface -= DrawGeneralParticles;
On.Terraria.Main.SetDisplayMode -= ResetRenderTargetSizes;
IL.Terraria.Main.DrawTiles -= DrawCustomLava;
IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw -= DrawCustomLava2;
+12
View File
@@ -538,6 +538,18 @@ namespace CalamityMod.ILEditing
}
#endregion Ash Particle Rendering
#region General Particle Rendering
private static void DrawGeneralParticles(On.Terraria.Main.orig_DrawInterface orig, Main self, GameTime gameTime)
{
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, default, null, null, Main.GameViewMatrix.ZoomMatrix);
GeneralParticleHandler.DrawAllParticles(Main.spriteBatch);
Main.spriteBatch.End();
orig(self, gameTime);
}
#endregion General Particle Rendering
#region Custom Lava Visuals
private static void ResetRenderTargetSizes(On.Terraria.Main.orig_SetDisplayMode orig, int width, int height, bool fullscreen)
{
+39 -15
View File
@@ -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++;
}
@@ -66,11 +83,18 @@ namespace CalamityMod.Particles
foreach (Particle particle in Particles.OrderBy(p => p.Time))
{
Vector2 drawPosition = basePosition - Main.screenPosition + particle.RelativeOffset;
Color particleColor = DetermineParticleColor(particle.Time / (float)particle.Lifetime);
Rectangle frame = ParticleTexture.Frame(1, ParticleFrameVariants, 0, particle.Variant);
if (particle.UseCustomDraw)
particle.CustomDraw(Main.spriteBatch);
else
{
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);
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

+50
View File
@@ -0,0 +1,50 @@
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;
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;
}
}
}
+1 -20
View File
@@ -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);
}
}
File renamed without changes.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

+48
View File
@@ -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;
}
}
}
+2 -19
View File
@@ -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);
}
}
+150
View File
@@ -0,0 +1,150 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Particles
{
public static class GeneralParticleHandler
{
private static List<Particle> particles;
private static int nextVacantIndex;
//Static list for details concerning every particle type
private static Dictionary<Type, int> particleTypes;
private static Dictionary<int, Texture2D> particleTextures;
private static List<Particle> particleInstances;
//Lists used when drawing particles batched
private static List<Particle> batchedAlphaBlendParticles;
private static List<Particle> batchedAdditiveBlendParticles;
internal static void Load()
{
particles = new List<Particle>();
particleTypes = new Dictionary<Type, int>();
particleTextures = new Dictionary<int, Texture2D>();
particleInstances = new List<Particle>();
batchedAlphaBlendParticles = new List<Particle>();
batchedAdditiveBlendParticles = new List<Particle>();
Type baseParticleType = typeof(Particle);
CalamityMod calamity = ModContent.GetInstance<CalamityMod>();
foreach (Type type in calamity.Code.GetTypes())
{
if (type.IsSubclassOf(baseParticleType) && !type.IsAbstract && type != baseParticleType)
{
int ID = particleTypes.Count; //Get the ID of the particle
particleTypes[type] = ID;
Particle instance = (Particle)FormatterServices.GetUninitializedObject(type);
particleInstances.Add(instance);
string texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name;
if (instance.Texture != "")
texturePath = instance.Texture;
particleTextures[ID] = ModContent.GetTexture(texturePath);
}
}
}
internal static void Unload()
{
particles = null;
particleTypes = null;
particleTextures = null;
particleInstances = null;
batchedAlphaBlendParticles = null;
batchedAdditiveBlendParticles = null;
}
/// <summary>
/// Spawns the particle instance provided into the world. If the particle limit is reached but the particle is marked as important, it will try to replace a non important particle.
/// </summary>
public static void SpawnParticle(Particle particle)
{
if (particles.Count >= CalamityConfig.Instance.ParticleLimit && !particle.Important)
return;
particles.Add(particle);
particle.Type = particleTypes[particle.GetType()];
}
public static void Update()
{
foreach (Particle particle in particles)
{
if (particle == null)
continue;
particle.Position += particle.Velocity;
particle.Time++;
particle.Update();
}
//Clear out particles whose time is up
particles.RemoveAll(particle => particle.Time >= particle.Lifetime && particle.SetLifetime);
}
public static void RemoveParticle(Particle particle)
{
particles.Remove(particle);
}
public static void DrawAllParticles(SpriteBatch sb)
{
//Batch the particles to avoid constant restarting of the spritebatch
foreach (Particle particle in particles)
{
if (particle == null)
continue;
if (particle.UseAdditiveBlend)
batchedAdditiveBlendParticles.Add(particle);
else
batchedAlphaBlendParticles.Add(particle);
}
foreach (Particle particle in batchedAlphaBlendParticles)
{
if (particle.UseCustomDraw)
particle.CustomDraw(sb);
else
{
Rectangle frame = particleTextures[particle.Type].Frame(1, particle.FrameVariants, 0, particle.Variant);
sb.Draw(particleTextures[particle.Type], particle.Position - Main.screenPosition, frame, particle.Color, particle.Rotation, frame.Size() * 0.5f, particle.Scale, SpriteEffects.None, 0f);
}
}
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, null, null, Main.GameViewMatrix.ZoomMatrix);
foreach (Particle particle in batchedAdditiveBlendParticles)
{
if (particle.UseCustomDraw)
particle.CustomDraw(sb);
else
{
Rectangle frame = particleTextures[particle.Type].Frame(1, particle.FrameVariants, 0, particle.Variant);
sb.Draw(particleTextures[particle.Type], particle.Position - Main.screenPosition, frame, particle.Color, particle.Rotation, frame.Size() * 0.5f, particle.Scale, SpriteEffects.None, 0f);
}
}
sb.End();
sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
batchedAlphaBlendParticles.Clear();
batchedAdditiveBlendParticles.Clear();
}
/// <summary>
/// Gives you the texture of the particle type. Useful for custom drawing
/// </summary>
public static Texture2D GetTexture(int type) => particleTextures[type];
private static string noteToEveryone = "This particle system was inspired by spirit mod's own particle system, with permission granted by Yuyutsu. Love you spirit mod! -Iban";
}
}
+55
View File
@@ -0,0 +1,55 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Particles
{
public class GenericSparkle : Particle
{
public override string Texture => "CalamityMod/Particles/Sparkle";
public override bool UseAdditiveBlend => true;
public override bool UseCustomDraw => true;
public override bool SetLifetime => true;
private float Spin;
private float opacity;
private Color Bloom;
private Color LightColor => Bloom * opacity;
private float BloomScale;
public GenericSparkle(Vector2 position, Vector2 velocity, Color color, Color bloom, float scale, int lifeTime, float rotationSpeed = 1f, float bloomScale = 1f)
{
Position = position;
Velocity = velocity;
Color = color;
Bloom = bloom;
Scale = scale;
Lifetime = lifeTime;
Rotation = Main.rand.NextFloat(MathHelper.TwoPi);
Spin = rotationSpeed;
BloomScale = bloomScale;
}
public override void Update()
{
opacity = (float)Math.Sin(LifetimeCompletion * MathHelper.Pi);
Lighting.AddLight(Position, LightColor.R / 255f, LightColor.G / 255f, LightColor.B / 255f);
Velocity *= 0.95f;
Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f);
}
public override void CustomDraw(SpriteBatch spriteBatch)
{
Texture2D starTexture = GeneralParticleHandler.GetTexture(Type);
Texture2D bloomTexture = ModContent.GetTexture("CalamityMod/Particles/BloomCircle");
//Ajust the bloom's texture to be the same size as the star's
float properBloomSize = (float)starTexture.Height / (float)bloomTexture.Height;
spriteBatch.Draw(bloomTexture, Position - Main.screenPosition, null, Bloom * opacity * 0.5f, 0, bloomTexture.Size()/2f, Scale * BloomScale * properBloomSize, SpriteEffects.None, 0);
spriteBatch.Draw(starTexture, Position - Main.screenPosition, null, Color * opacity * 0.5f, Rotation + MathHelper.PiOver4, starTexture.Size() / 2f, Scale * 0.75f, SpriteEffects.None, 0);
spriteBatch.Draw(starTexture, Position - Main.screenPosition, null, Color * opacity, Rotation, starTexture.Size() / 2f, Scale, SpriteEffects.None, 0);
}
}
}
File renamed without changes.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 408 B

After

Width:  |  Height:  |  Size: 408 B

+70 -11
View File
@@ -1,21 +1,80 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace CalamityMod.Particles
{
public class Particle
{
/// <summary>
/// The ID of the particle inside of the general particle handler's array. This is set automatically when the particle is created
/// </summary>
public int ID;
/// <summary>
/// The ID of the particle type as registered by the general particle handler. This is set automatically when the particle handler loads
/// </summary>
public int Type;
/// <summary>
/// The amount of frames this particle has existed for. You shouldn't have to touch this manually.
/// </summary>
public int Time;
public int Lifetime;
public int Variant;
public float Scale;
/// <summary>
/// Set this to true if you NEED the particle to render even if the particle cap is reached.
/// </summary>
public virtual bool Important => false;
/// <summary>
/// Set this to true if you want your particle to automatically get removed when its time reaches its maximum lifetime
/// </summary>
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 float LifetimeCompletion => Lifetime != 0 ? Time / (float)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
/// </summary>
public Vector2 RelativeOffset;
public Particle(int lifetime, Vector2 relativeOffset, float scale, int variant = 0)
{
Time = 0;
Lifetime = lifetime;
Variant = variant;
Scale = scale;
RelativeOffset = relativeOffset;
}
/// <summary>
/// The inworld position of a particle. Keep in mind this isn't used in the context of a Particle Set, since all the particles work off their relative position to the set's origin
/// </summary>
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.
/// </summary>
public virtual bool UseCustomDraw => false;
/// <summary>
/// Use this method if you want to handle the particle drawing yourself. Only called if Particle.UseCustomDraw is set to true.
/// </summary>
public virtual void CustomDraw(SpriteBatch spriteBatch) { }
/// <summary>
/// Called for every update of the particle handler.
/// The particle's velocity gets automatically added to its position, and its time automatically increases.
/// </summary>
public virtual void Update() { }
/// <summary>
/// Set this to true to make your particle use additive blending instead of alphablend.
/// </summary>
public virtual bool UseAdditiveBlend => false;
/// <summary>
/// Removes the particle from the handler
/// </summary>
public void Kill() => GeneralParticleHandler.RemoveParticle(this);
}
}
File renamed without changes.

Before

Width:  |  Height:  |  Size: 208 B

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

+48
View File
@@ -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, LifetimeCompletion, true);
Color *= opacity;
}
}
}
+4 -22
View File
@@ -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);
}
}