From e25746c07c5c0d382a457029cb4cc430e31df0b2 Mon Sep 17 00:00:00 2001 From: DominicKarma <51094361+DominicKarma@users.noreply.github.com> Date: Mon, 21 Jun 2021 03:52:20 +0200 Subject: [PATCH] Particle system port + Thanatos smoke --- ExtraTextures/ThanatosVentParticle.png | Bin 0 -> 408 bytes Gores/Thanatos/ThanatosVentParticle1.cs | 35 ----------- Gores/Thanatos/ThanatosVentParticle1.png | Bin 268 -> 0 bytes Gores/Thanatos/ThanatosVentParticle2.cs | 35 ----------- Gores/Thanatos/ThanatosVentParticle2.png | Bin 259 -> 0 bytes Gores/Thanatos/ThanatosVentParticle3.cs | 35 ----------- Gores/Thanatos/ThanatosVentParticle3.png | Bin 254 -> 0 bytes NPCs/ExoMechs/Thanatos/ThanatosBody1.cs | 15 +++-- NPCs/ExoMechs/Thanatos/ThanatosBody2.cs | 15 +++-- NPCs/ExoMechs/Thanatos/ThanatosHead.cs | 2 +- NPCs/ExoMechs/Thanatos/ThanatosTail.cs | 2 +- Particles/BaseParticleSet.cs | 77 +++++++++++++++++++++++ Particles/Particle.cs | 21 +++++++ Particles/ThanatosSmokeParticleSet.cs | 36 +++++++++++ 14 files changed, 156 insertions(+), 117 deletions(-) create mode 100644 ExtraTextures/ThanatosVentParticle.png delete mode 100644 Gores/Thanatos/ThanatosVentParticle1.cs delete mode 100644 Gores/Thanatos/ThanatosVentParticle1.png delete mode 100644 Gores/Thanatos/ThanatosVentParticle2.cs delete mode 100644 Gores/Thanatos/ThanatosVentParticle2.png delete mode 100644 Gores/Thanatos/ThanatosVentParticle3.cs delete mode 100644 Gores/Thanatos/ThanatosVentParticle3.png create mode 100644 Particles/BaseParticleSet.cs create mode 100644 Particles/Particle.cs create mode 100644 Particles/ThanatosSmokeParticleSet.cs diff --git a/ExtraTextures/ThanatosVentParticle.png b/ExtraTextures/ThanatosVentParticle.png new file mode 100644 index 0000000000000000000000000000000000000000..a66a5aa74328375c6d1ff3c4a234a6876490d850 GIT binary patch literal 408 zcmeAS@N?(olHy`uVBq!ia0vp^3P7C3!3-qlE=}GJq!^2X+?^QKos)S9a|ZZ?xB}_jyLSW0IIdqWfE05{kYDis{|whp@dDK{a29w(7BevL9R^{> zdQ#qcS=)|@J$n6yxtliBpWN9{w4QC&gW~D` z1+RIjS=(z(c3r`h-p}50s&=7~)`Jf=ax0jeuN`o57FK#99Fd;Ev?}U2SFhHV(nVbR zUM=9XGdDQ;Y&DZZt-r?GxRd6mYtYei`{;~Tj8>T zA7zsh>;h_bVwMC9g%F8|Po$t#tP6izifxV-H~$%jeZ39tDA4wN$95$B7aWTW(@ xK4bys!Y5N!Fx}LO=;v^p_Mq#+r_#iE_rp_!j=HW_X#<87gQu&X%Q~loCII2hn7IG| literal 0 HcmV?d00001 diff --git a/Gores/Thanatos/ThanatosVentParticle1.cs b/Gores/Thanatos/ThanatosVentParticle1.cs deleted file mode 100644 index 6d83177eaa..0000000000 --- a/Gores/Thanatos/ThanatosVentParticle1.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Gores -{ - public class ThanatosVentParticle1 : ModGore - { - public override void OnSpawn(Gore gore) - { - gore.sticky = false; - } - - public override bool Update(Gore gore) - { - if (Main.netMode == NetmodeID.Server || !gore.active) - return false; - - gore.velocity *= 0.98f; - gore.scale -= 0.007f; - if (gore.scale < 0.1f) - { - gore.scale = 0.1f; - gore.alpha = 255; - } - - gore.position += gore.velocity; - - if (gore.alpha >= 255) - gore.active = false; - - return false; - } - } -} diff --git a/Gores/Thanatos/ThanatosVentParticle1.png b/Gores/Thanatos/ThanatosVentParticle1.png deleted file mode 100644 index ec84d9232c5259734bd986fe5a6b8218a2c2a272..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 268 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}$2?seLn2z= zPInY)P~dRg?;HO4irhIf%cYGTPY)d0pLvYyN#hE}rXa7k0e15pe|=vkp=`M?v**kN ziKD#^X?C2=?-^}8e<(UUnH3z(9P?z2{sW~%zXbJTOSG=L-P@Y&m#~Cw%S684EH;7~ zQW4+lf1YVzX4;+f_y1ak3WbLBb)mcGI4y}4XR+A(wqlOQB|VM;%lTK?wSGTiS+O^v z?8($KoNItEVD5)(_MG2d-}fc>Ehtygx-{>1== 255) - gore.active = false; - - return false; - } - } -} diff --git a/Gores/Thanatos/ThanatosVentParticle2.png b/Gores/Thanatos/ThanatosVentParticle2.png deleted file mode 100644 index 50a693e93ee236dd2c6c368254cda072ef00c849..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 259 zcmV+e0sQ`nP)Px#y-7qtR9J=Wmq8AIAPfYl@oT)A$LXmFG%OSZDbYD;6O>(ADC7ho1Q|kHAWrd% z_rCa%L;JT`ocxec&I$>{5olZ%I}Suhg-wbiD5p3#Ogg|yrSjU^BjmWmNs|sRqm|1z zIcL;?Ud3IQa$vM_ltcSe!BdLLndJ_=If2V%^6XO%*qlII1+~4uwKGy-$^iy-KB%s> zPT1TBV4oNDay5lby`sD)EO%hWS&(!*``nBQsLpjoJj-$ier|*NB~JSeq{;vQ002ov JPDHLkV1g)zXnp_y diff --git a/Gores/Thanatos/ThanatosVentParticle3.cs b/Gores/Thanatos/ThanatosVentParticle3.cs deleted file mode 100644 index 1eee878087..0000000000 --- a/Gores/Thanatos/ThanatosVentParticle3.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Gores -{ - public class ThanatosVentParticle3 : ModGore - { - public override void OnSpawn(Gore gore) - { - gore.sticky = false; - } - - public override bool Update(Gore gore) - { - if (Main.netMode == NetmodeID.Server || !gore.active) - return false; - - gore.velocity *= 0.98f; - gore.scale -= 0.007f; - if (gore.scale < 0.1f) - { - gore.scale = 0.1f; - gore.alpha = 255; - } - - gore.position += gore.velocity; - - if (gore.alpha >= 255) - gore.active = false; - - return false; - } - } -} \ No newline at end of file diff --git a/Gores/Thanatos/ThanatosVentParticle3.png b/Gores/Thanatos/ThanatosVentParticle3.png deleted file mode 100644 index 221e95e9487e35eb26f7cde9998aef8d2bc3df8b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 254 zcmVPx#xJg7oR9J=Wm(dQu5DZ1HWxwXDeVo0ph_JS%X_M`~co>~~N)bRPr9^e9%B2ke z5MyKwI=Iobbk05uoaa$L6vs^~k~x9E$nnhiG^V7pIe~T!^iG#@if%Vh@m&$iSF(P0ftK^W9t`V>3j*4Dtgz+;EGCfAQ28VQe-j8;Kl`^#z*M8t zkh=X=ZKV!Z07*qoM6N<$ Ef|xF7<^TWy diff --git a/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs b/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs index 86e7cd7fb3..14694e9bc7 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs @@ -1,6 +1,7 @@ using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Events; +using CalamityMod.Particles; using CalamityMod.Projectiles.Boss; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -17,6 +18,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos { // Whether the body is venting heat or not, it is vulnerable to damage during venting private bool vulnerable = false; + public ThanatosSmokeParticleSet SmokeDrawer = new ThanatosSmokeParticleSet(-1, 4, 0f, 16f, 1.5f); public override void SetStaticDefaults() { @@ -323,6 +325,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos npc.Calamity().unbreakableDR = !vulnerable; // Vent noise and steam + SmokeDrawer.ParticleSpawnRate = 9999999; if (vulnerable) { // Noise @@ -331,17 +334,18 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos // Steam float maxSteamTime = 180f; - int maxGores = 4; npc.localAI[0] += 1f; - if (npc.localAI[0] < maxSteamTime && npc.localAI[0] % 18f == 0f) + if (npc.localAI[0] < maxSteamTime) { - int goreAmt = maxGores - (int)Math.Round(npc.localAI[0] / 60f); - CalamityUtils.ExplosionGores(npc.Center, goreAmt, true, npc.velocity); + SmokeDrawer.BaseMoveRotation = npc.rotation - MathHelper.PiOver2; + SmokeDrawer.ParticleSpawnRate = 3; } } else npc.localAI[0] = 0f; + SmokeDrawer.Update(); + Vector2 vector18 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); float num191 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2); float num192 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2); @@ -461,11 +465,12 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos Vector2 center = npc.Center - Main.screenPosition; center -= new Vector2(texture.Width, texture.Height / Main.npcFrameCount[npc.type]) * npc.scale / 2f; - center += vector * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + center += vector * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture, center, npc.frame, npc.GetAlpha(drawColor), npc.rotation, vector, npc.scale, spriteEffects, 0f); texture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosBody1Glow"); spriteBatch.Draw(texture, center, npc.frame, Color.White * npc.Opacity, npc.rotation, vector, npc.scale, spriteEffects, 0f); + SmokeDrawer.DrawSet(npc.Center); } public override bool CheckActive() => false; diff --git a/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs b/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs index a56561eb56..5c6f60fbc2 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs @@ -1,6 +1,7 @@ using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Events; +using CalamityMod.Particles; using CalamityMod.Projectiles.Boss; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -17,6 +18,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos { // Whether the body is venting heat or not, it is vulnerable to damage during venting private bool vulnerable = false; + public ThanatosSmokeParticleSet SmokeDrawer = new ThanatosSmokeParticleSet(-1, 4, 0f, 16f, 1.5f); public override void SetStaticDefaults() { @@ -323,6 +325,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos npc.Calamity().unbreakableDR = !vulnerable; // Vent noise and steam + SmokeDrawer.ParticleSpawnRate = 9999999; if (vulnerable) { // Noise @@ -331,17 +334,18 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos // Steam float maxSteamTime = 180f; - int maxGores = 4; npc.localAI[0] += 1f; - if (npc.localAI[0] < maxSteamTime && npc.localAI[0] % 18f == 0f) + if (npc.localAI[0] < maxSteamTime) { - int goreAmt = maxGores - (int)Math.Round(npc.localAI[0] / 60f); - CalamityUtils.ExplosionGores(npc.Center, goreAmt, true, npc.velocity); + SmokeDrawer.BaseMoveRotation = npc.rotation - MathHelper.PiOver2; + SmokeDrawer.ParticleSpawnRate = 3; } } else npc.localAI[0] = 0f; + SmokeDrawer.Update(); + Vector2 vector18 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); float num191 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2); float num192 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2); @@ -461,11 +465,12 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos Vector2 center = npc.Center - Main.screenPosition; center -= new Vector2(texture.Width, texture.Height / Main.npcFrameCount[npc.type]) * npc.scale / 2f; - center += vector * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + center += vector * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture, center, npc.frame, npc.GetAlpha(drawColor), npc.rotation, vector, npc.scale, spriteEffects, 0f); texture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosBody2Glow"); spriteBatch.Draw(texture, center, npc.frame, Color.White * npc.Opacity, npc.rotation, vector, npc.scale, spriteEffects, 0f); + SmokeDrawer.DrawSet(npc.Center); } public override bool CheckActive() => false; diff --git a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs index e1b3d158dd..fc7a8922be 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs @@ -772,7 +772,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos Vector2 center = npc.Center - Main.screenPosition; center -= new Vector2(texture.Width, texture.Height / Main.npcFrameCount[npc.type]) * npc.scale / 2f; - center += vector * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + center += vector * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture, center, npc.frame, npc.GetAlpha(drawColor), npc.rotation, vector, npc.scale, spriteEffects, 0f); texture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosHeadGlow"); diff --git a/NPCs/ExoMechs/Thanatos/ThanatosTail.cs b/NPCs/ExoMechs/Thanatos/ThanatosTail.cs index a863e5c35c..e19759e911 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosTail.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosTail.cs @@ -461,7 +461,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos Vector2 center = npc.Center - Main.screenPosition; center -= new Vector2(texture.Width, texture.Height / Main.npcFrameCount[npc.type]) * npc.scale / 2f; - center += vector * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + center += vector * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture, center, npc.frame, npc.GetAlpha(drawColor), npc.rotation, vector, npc.scale, spriteEffects, 0f); texture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosTailGlow"); diff --git a/Particles/BaseParticleSet.cs b/Particles/BaseParticleSet.cs new file mode 100644 index 0000000000..8490181b26 --- /dev/null +++ b/Particles/BaseParticleSet.cs @@ -0,0 +1,77 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using Terraria; +using Terraria.ID; + +namespace CalamityMod.Particles +{ + public abstract class BaseParticleSet + { + public int LocalTimer { get; internal set; } + public int SetLifetime { get; internal set; } + public int ParticleSpawnRate; + public List Particles = new List(); + public abstract int ParticleLifetime { get; } + public abstract void UpdateBehavior(Particle particle); + 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) + { + SetLifetime = setLifetime; + ParticleSpawnRate = particleSpawnRate; + } + + public virtual void Update() + { + // Don't perform any operations on the server. Doing so would be a waste of space as these sets are entirely based on drawcode. + if (Main.netMode == NetmodeID.Server) + return; + + bool closeToDeath = LocalTimer >= SetLifetime - ParticleLifetime && SetLifetime > 0; + if (LocalTimer % ParticleSpawnRate == 0 && !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++) + { + Particles[i].Time++; + UpdateBehavior(Particles[i]); + } + + // Clear all expired particles. + Particles.RemoveAll(particle => particle.Time >= particle.Lifetime); + LocalTimer++; + } + + public virtual void DrawSet(Vector2 basePosition) + { + if (Main.netMode == NetmodeID.Server) + return; + + IEnumerable orderedParticles = Particles; + if (OrderFunction != null) + orderedParticles = orderedParticles.OrderBy(OrderFunction); + + 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); + + Main.spriteBatch.Draw(ParticleTexture, drawPosition, frame, particleColor, 0f, frame.Size() * 0.5f, particle.Scale, SpriteEffects.None, 0f); + } + } + } +} \ No newline at end of file diff --git a/Particles/Particle.cs b/Particles/Particle.cs new file mode 100644 index 0000000000..cf3bac931f --- /dev/null +++ b/Particles/Particle.cs @@ -0,0 +1,21 @@ +using Microsoft.Xna.Framework; + +namespace CalamityMod.Particles +{ + public class Particle + { + public int Time; + public int Lifetime; + public int Variant; + public float Scale; + public Vector2 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/Particles/ThanatosSmokeParticleSet.cs b/Particles/ThanatosSmokeParticleSet.cs new file mode 100644 index 0000000000..dba17d45f6 --- /dev/null +++ b/Particles/ThanatosSmokeParticleSet.cs @@ -0,0 +1,36 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class ThanatosSmokeParticleSet : BaseParticleSet + { + public float SpawnAreaCompactness; + public float RelativePower; + public float BaseMoveRotation; + public float MoveRotationOffset; + public override int ParticleLifetime => 50; + 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) + { + MoveRotationOffset = Main.rand.NextFloat(-0.36f, 0.36f); + BaseMoveRotation = baseMoveRotation; + SpawnAreaCompactness = spawnAreaCompactness; + RelativePower = relativePower; + } + + public override void UpdateBehavior(Particle particle) + { + particle.Scale += RelativePower * 0.02f; + particle.RelativeOffset -= (BaseMoveRotation + Main.rand.NextFloat(-0.38f, 0.38f)).ToRotationVector2() * RelativePower * 4.5f; + } + + public override Color DetermineParticleColor(float lifetimeCompletion) => Color.White * Utils.InverseLerp(1f, 0.85f, lifetimeCompletion, true); + + public override Particle SpawnParticle() => new Particle(ParticleLifetime, Main.rand.NextVector2Circular(1f, 1f) * SpawnAreaCompactness, 0.06f, Main.rand.Next(3)); + } +} \ No newline at end of file