Thruster FX

This commit is contained in:
Nathanael Overton committed 2026-02-16 18:37:25 -05:00
1 parent f285dd88af
commit bee2e7c822
4 files changed
+276 -44

No files matched your search

+26 -1
View File
@@ -40,6 +40,8 @@ namespace CalamityMod.CalPlayer.Dashes
public override void OnDashEffects(Player player)
{
Time = 0;
// Burst of evenly spaced but random velocity dusts
for (int m = 0; m < 6; m++)
{
float fxFade = Utils.GetLerpValue(5, 15, Math.Abs(player.velocity.X), true);
@@ -55,6 +57,29 @@ namespace CalamityMod.CalPlayer.Dashes
dust2.noGravity = true;
dust2.fadeIn = 0.5f;
}
// Thruster prim
int beamCount = 3;
float maxAngle = MathHelper.ToRadians(10f);
Vector2 baseDir = -player.velocity.SafeNormalize(Vector2.UnitX);
for (int i = -1; i < beamCount; i++)
{
float t = i / (float)(beamCount - 1);
float centered = t * 2f - 1f;
float angleOffset = centered * maxAngle;
Vector2 dir = baseDir.RotatedBy(angleOffset);
float sizeFactor = 1f - Math.Abs(centered) * 0.7f;
ThrusterParticle particle = new ThrusterParticle(player, dir, 16, 120f * sizeFactor, 1);
GeneralParticleHandler.SpawnParticle(particle, false, GeneralDrawLayer.BeforeProjectiles);
}
SoundStyle sound = V8000Engine.DashSound;
SoundEngine.PlaySound(sound with { Volume = 0.5f, Pitch = Main.rand.NextFloat(-0.4f, -0.3f) }, player.Center);
}
@@ -79,7 +104,7 @@ namespace CalamityMod.CalPlayer.Dashes
Color primaryColor = Color.Lerp(Color.DodgerBlue, Color.LightSkyBlue, fadeInLerp);
Particle beamBody = new CustomSpark(player.Center, -player.velocity * 0.15f, "CalamityMod/Particles/BloomCircle", false, 7, 0.65f - 0.3f * fadeInLerp, primaryColor * 0.8f, new Vector2(1.1f - 0.4f * fadeInLerp, 0.8f + 0.6f * fadeInLerp), true, true, shrinkSpeed: 0.6f);
GeneralParticleHandler.SpawnParticle(beamBody);
Particle beamCore = new CustomSpark(player.Center, -player.velocity * 0.15f, "CalamityMod/Particles/BloomCircle", false, 5, 0.35f - 0.15f * fadeInLerp, Color.Lerp(primaryColor, Color.White, 0.6f), new Vector2(0.7f, 1.4f), true, true, shrinkSpeed: 0.6f);
Particle beamCore = new CustomSpark(player.Center, -player.velocity * 0.15f, "CalamityMod/Particles/BloomCircle", false, 5, 0.35f - 0.15f * fadeInLerp, Color.Lerp(primaryColor, Color.White, 0.6f), new Vector2(0.5f, 1.4f), true, true, shrinkSpeed: 0.6f);
GeneralParticleHandler.SpawnParticle(beamCore);
// Horizontal dust
+31 -3
View File
@@ -1,12 +1,15 @@
using System;
using CalamityMod.Dusts;
using CalamityMod.Enums;
using CalamityMod.Graphics.Renderers;
using CalamityMod.Items.Accessories;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.GameContent.Drawing;
using Terraria.GameContent.Items;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
@@ -32,6 +35,8 @@ namespace CalamityMod.CalPlayer.Dashes
public override void OnDashEffects(Player player)
{
Time = 0;
// Burst of evenly spaced but random velocity dusts
for (int m = 0; m < 6; m++)
{
float fxFade = Utils.GetLerpValue(5, 15, Math.Abs(player.velocity.X), true);
@@ -41,12 +46,35 @@ namespace CalamityMod.CalPlayer.Dashes
Color trailColor = Main.rand.NextBool(3) ? Color.Firebrick : Color.OrangeRed;
int dustStyle = ModContent.DustType<SquashDust>();
Dust dust2 = Dust.NewDustPerfect(trailPos, dustStyle, -player.velocity.SafeNormalize(Vector2.UnitX) * Main.rand.NextFloat(4, 13));
dust2.scale = Main.rand.NextFloat(0.75f, 1.2f);
Dust dust2 = Dust.NewDustPerfect(trailPos, dustStyle, -player.velocity.SafeNormalize(Vector2.UnitX) * Main.rand.NextFloat(5, 16));
dust2.scale = Main.rand.NextFloat(0.8f, 1.3f);
dust2.color = trailColor;
dust2.noGravity = true;
dust2.fadeIn = 0.5f;
}
// Thruster prim
int beamCount = 3;
float maxAngle = MathHelper.ToRadians(10f);
Vector2 baseDir = -player.velocity.SafeNormalize(Vector2.UnitX);
for (int i = -1; i < beamCount; i++)
{
float t = i / (float)(beamCount - 1);
float centered = t * 2f - 1f;
float angleOffset = centered * maxAngle;
Vector2 dir = baseDir.RotatedBy(angleOffset);
float sizeFactor = 1f - Math.Abs(centered) * 0.7f;
ThrusterParticle particle = new ThrusterParticle(player, dir, 12, 100f * sizeFactor, 0);
GeneralParticleHandler.SpawnParticle(particle, false, GeneralDrawLayer.BeforeProjectiles);
}
SoundStyle sound = V8Engine.DashSound;
SoundEngine.PlaySound(sound with { Volume = 0.5f, Pitch = Main.rand.NextFloat(-0.4f, -0.3f) }, player.Center);
}
@@ -70,7 +98,7 @@ namespace CalamityMod.CalPlayer.Dashes
Color primaryColor = Color.Lerp(Color.Firebrick, Color.OrangeRed, fadeInLerp);
Particle beamBody = new CustomSpark(player.Center, -player.velocity * 0.15f, "CalamityMod/Particles/BloomCircle", false, 7, 0.65f - 0.3f * fadeInLerp, primaryColor * 0.8f, new Vector2(1.1f - 0.4f * fadeInLerp, 0.8f + 0.6f * fadeInLerp), true, false, shrinkSpeed: 0.6f);
GeneralParticleHandler.SpawnParticle(beamBody);
Particle beamCore = new CustomSpark(player.Center, -player.velocity * 0.15f, "CalamityMod/Particles/BloomCircle", false, 5, 0.35f - 0.15f * fadeInLerp, Color.Lerp(primaryColor, Color.White, 0.6f), new Vector2(0.7f, 1.4f), true, false, shrinkSpeed: 0.6f);
Particle beamCore = new CustomSpark(player.Center, -player.velocity * 0.15f, "CalamityMod/Particles/BloomCircle", false, 5, 0.35f - 0.15f * fadeInLerp, Color.Lerp(primaryColor, Color.White, 0.6f), new Vector2(0.5f, 1.2f), true, false, shrinkSpeed: 0.6f);
GeneralParticleHandler.SpawnParticle(beamCore);
+219
View File
@@ -0,0 +1,219 @@
using System;
using CalamityMod.Enums;
using CalamityMod.Items.Accessories;
using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using rail;
using Terraria;
using Terraria.Audio;
using Terraria.ModLoader;
namespace CalamityMod.Particles
{
public class ThrusterParticle : Particle
{
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override bool SetLifetime => true;
public override bool UseCustomDraw => true;
public Vector2[] Path = new Vector2[2];
public Vector2 DashDirection;
private VertexPositionColorTexture[] vertices;
private BasicEffect effect;
private Vector2 lastPlayerCenter;
private Vector2[] pos = new Vector2[20];
public float length;
private int time;
private Player Owner;
private int ColorSelection;
private static readonly Color[] V8Colors =
{
Color.White,
Color.Yellow,
Color.OrangeRed,
Color.Red,
Color.Transparent
};
private static readonly Color[] V8000Colors =
{
Color.White,
Color.LightBlue,
Color.LightCyan,
Color.Cyan,
Color.Transparent
};
Vector2 GetPlayerDrawCenter(Player p)
{
return p.Center + new Vector2(0f, p.gfxOffY);
}
public ThrusterParticle(Player player, Vector2 direction, int lifetime, float scale, int colors)
{
Owner = player;
Position = player.Center;
Velocity = direction;
Scale = scale;
Lifetime = lifetime;
ColorSelection = colors;
Vector2 start = GetPlayerDrawCenter(player);
Vector2 dir = direction;
if (dir == Vector2.Zero)
dir = Vector2.UnitX;
dir.Normalize();
length = scale;
Vector2 tip = start + dir * length;
for (int i = 0; i < pos.Length; i++)
{
float t = i / (float)(pos.Length - 1);
pos[i] = Vector2.Lerp(start, tip, t);
}
lastPlayerCenter = start;
}
public override void Update()
{
Path[0] = GetPlayerDrawCenter(Owner);
Path[^1] = Position;
float lifeProgress = 1f - (time / (float)Lifetime);
if (lifeProgress < 0f)
lifeProgress = 0f;
if (lifeProgress > 1f)
lifeProgress = 1f;
time++;
}
private Color SampleGradient(float t)
{
Color[] ThrusterGradient = ColorSelection == 1 ? V8000Colors : V8Colors;
t = MathHelper.Clamp(t, 0, 1);
float scaled = t * (ThrusterGradient.Length - 1);
int index = (int)scaled;
int next = Math.Min(index + 1, ThrusterGradient.Length - 1);
float interp = scaled - index;
return Color.Lerp(ThrusterGradient[index], ThrusterGradient[next], interp);
}
private void BuildPrimitive()
{
int count = pos.Length - 1;
if (vertices == null || vertices.Length != count * 2)
vertices = new VertexPositionColorTexture[count * 2];
float width = 18f;
float lifeProgress = 1f - (time / (float)Lifetime);
float widthFactor = MathF.Sin(lifeProgress);
for (int i = 0; i < count; i++)
{
Vector2 current = pos[i];
Vector2 direction;
if (i == count - 1)
direction = pos[i] - pos[i - 1];
else
direction = pos[i + 1] - pos[i];
if (direction == Vector2.Zero)
direction = Vector2.UnitX;
direction.Normalize();
Vector2 normal = direction.RotatedBy(MathHelper.PiOver2);
float progress = i / (float)(count - 1);
float profile = 0;
if (length < 100)
profile = (float)Math.Sinh(progress * MathHelper.PiOver2) * 1.8f + 0.2f;
else
profile = (float)Math.Sin(progress * Math.PI) * 0.8f + 0.2f;
float scaledWidth = width * profile * widthFactor;
Vector2 left = current - normal * scaledWidth;
Vector2 right = current + normal * scaledWidth;
Color color = SampleGradient(progress);
vertices[i * 2] = new VertexPositionColorTexture(
new Vector3(left - Main.screenPosition, 0),
color,
new Vector2(progress, 0));
vertices[i * 2 + 1] = new VertexPositionColorTexture(
new Vector3(right - Main.screenPosition, 0),
color,
new Vector2(progress, 1));
}
}
public override void CustomDraw(SpriteBatch spriteBatch)
{
if (pos == null || pos.Length < 2)
return;
Vector2 drawCenter = GetPlayerDrawCenter(Owner);
Vector2 delta = drawCenter - lastPlayerCenter;
for (int i = 0; i < pos.Length; i++)
pos[i] += delta;
lastPlayerCenter = drawCenter;
BuildPrimitive();
GraphicsDevice device = Main.graphics.GraphicsDevice;
RasterizerState rasterizer = new RasterizerState { CullMode = CullMode.None, FillMode = FillMode.Solid };
effect ??= new BasicEffect(device)
{
VertexColorEnabled = true,
TextureEnabled = false,
Projection = Matrix.CreateOrthographicOffCenter(
0,
Main.screenWidth,
Main.screenHeight,
0,
-1,
1)
};
effect.World = Matrix.Identity;
effect.View = Main.GameViewMatrix.ZoomMatrix;
device.RasterizerState = rasterizer;
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.PointWrap, default, device.RasterizerState, null, Main.GameViewMatrix.TransformationMatrix);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
device.DrawUserPrimitives(
PrimitiveType.TriangleStrip,
vertices,
0,
vertices.Length - 2);
}
}
}
}
-40
View File
@@ -1,40 +0,0 @@
using System;
using CalamityMod.Enums;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;
using static CalamityMod.CalamityUtils;
namespace CalamityMod.Particles
{
public class V8ThrusterParticle : Particle
{
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override bool SetLifetime => true;
public override bool UseCustomDraw => true;
public Vector2[] Path = new Vector2[2];
public Vector2 DashDirection;
private VertexPositionColorTexture[] vertices;
private BasicEffect effect;
public V8ThrusterParticle(Vector2 relativePosition, Vector2 velocity, /*Vector2 dashDirection,*/ int lifetime, float scale, Color color)
{
Position = relativePosition;
Velocity = velocity;
Scale = scale;
// DashDirection = dashDirection;
Lifetime = lifetime;
Color = color;
}
public override void Update()
{
Path[0] = Main.LocalPlayer.Center;
Path[^1] = Position;
}
}
}