Particle system port + Thanatos smoke

This commit is contained in:
DominicKarma committed 2021-06-21 03:52:20 +02:00
1 parent 40ecb9395f
commit e25746c07c
14 files changed
+156 -117

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 B

-35
View File
@@ -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;
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 268 B

-35
View File
@@ -1,35 +0,0 @@
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Gores
{
public class ThanatosVentParticle2 : 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;
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 B

-35
View File
@@ -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;
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 B

+10 -5
View File
@@ -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;
+10 -5
View File
@@ -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;
+1 -1
View File
@@ -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");
+1 -1
View File
@@ -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");
+77
View File
@@ -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<Particle> Particles = new List<Particle>();
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<Particle, int> 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<Particle> 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);
}
}
}
}
+21
View File
@@ -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;
}
}
}
+36
View File
@@ -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));
}
}