Started working on a glowier telegraph for ares's cannons

This commit is contained in:
IbanPlay authored and Cameron Ewell committed 2022-01-29 01:22:50 -05:00
1 parent d0510cc9da
commit 7c3893267d
7 files changed
+194 -5

No files matched your search

+3
View File
@@ -85,6 +85,9 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
// Spawn rate for enrage steam
public const int ventCloudSpawnRate = 3;
// Spawn rate for telegraph particles
public const int telegraphParticlesSpawnRate = 5;
// Number of frames on the X and Y axis
private const int maxFramesX = 6;
private const int maxFramesY = 8;
+55 -4
View File
@@ -8,6 +8,7 @@ using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
@@ -28,6 +29,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
}
public ThanatosSmokeParticleSet SmokeDrawer = new ThanatosSmokeParticleSet(-1, 3, 0f, 16f, 1.5f);
public AresCannonChargeParticleSet EnergyDrawer = new AresCannonChargeParticleSet(-1, 15, 40f, Color.Aqua);
// Number of frames on the X and Y axis
private const int maxFramesX = 6;
@@ -367,6 +369,7 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
SmokeDrawer.Update();
EnergyDrawer.ParticleSpawnRate = 9999999;
// Attacking phases
switch ((int)AIState)
{
@@ -400,6 +403,10 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
// Y = 4 sets to frame 12
frameY = 4;
}
EnergyDrawer.ParticleSpawnRate = AresBody.telegraphParticlesSpawnRate;
EnergyDrawer.SpawnAreaCompactness = 500f;
}
else
{
@@ -432,6 +439,8 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
break;
}
EnergyDrawer.Update();
// Movement
// Inverse lerp returns the percentage of progress between A and B
float lerpValue = Utils.InverseLerp(movementDistanceGateValue, 2400f, distanceFromDestination.Length(), true);
@@ -534,9 +543,30 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
}
Vector2 center = npc.Center - Main.screenPosition;
//Draw an outline to the arm when it charges up
if ((npc.Calamity().newAI[2] < teslaOrbTelegraphDuration) && AIState == (float)Phase.TeslaOrbs)
{
CalamityUtils.EnterShaderRegion(spriteBatch);
Color outlineColor = Color.Lerp(Color.Aqua, Color.White, npc.Calamity().newAI[2] / teslaOrbTelegraphDuration);
float outlineThickness = MathHelper.Clamp(npc.Calamity().newAI[2] / teslaOrbTelegraphDuration * 4f, 0f, 3f);
GameShaders.Misc["CalamityMod:BasicTint"].UseOpacity(1f);
GameShaders.Misc["CalamityMod:BasicTint"].UseColor(outlineColor);
GameShaders.Misc["CalamityMod:BasicTint"].Apply();
for (float i = 0; i < 1; i += 0.125f)
{
spriteBatch.Draw(texture, center + (i * MathHelper.TwoPi + npc.rotation).ToRotationVector2() * outlineThickness, frame, outlineColor, npc.rotation, vector, npc.scale, spriteEffects, 0f);
}
CalamityUtils.ExitShaderRegion(spriteBatch);
}
spriteBatch.Draw(texture, center, frame, npc.GetAlpha(drawColor), npc.rotation, vector, npc.scale, spriteEffects, 0f);
texture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Ares/AresTeslaCannonGlow");
Texture2D glowTexture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Ares/AresTeslaCannonGlow");
if (CalamityConfig.Instance.Afterimages)
{
@@ -547,13 +577,34 @@ namespace CalamityMod.NPCs.ExoMechs.Ares
afterimageColor = npc.GetAlpha(afterimageColor);
afterimageColor *= (numAfterimages - i) / 15f;
Vector2 afterimageCenter = npc.oldPos[i] + new Vector2(npc.width, npc.height) / 2f - Main.screenPosition;
afterimageCenter -= new Vector2(texture.Width, texture.Height) / new Vector2(maxFramesX, maxFramesY) * npc.scale / 2f;
afterimageCenter -= new Vector2(glowTexture.Width, glowTexture.Height) / new Vector2(maxFramesX, maxFramesY) * npc.scale / 2f;
afterimageCenter += vector * npc.scale + new Vector2(0f, npc.gfxOffY);
spriteBatch.Draw(texture, afterimageCenter, npc.frame, afterimageColor, npc.oldRot[i], vector, npc.scale, spriteEffects, 0f);
spriteBatch.Draw(glowTexture, afterimageCenter, npc.frame, afterimageColor, npc.oldRot[i], vector, npc.scale, spriteEffects, 0f);
}
}
spriteBatch.Draw(texture, center, frame, afterimageBaseColor * npc.Opacity, npc.rotation, vector, npc.scale, spriteEffects, 0f);
spriteBatch.Draw(glowTexture, center, frame, afterimageBaseColor * npc.Opacity, npc.rotation, vector, npc.scale, spriteEffects, 0f);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
//Update the parameters
//Draw a pulsing version of the thing above the arm
if ((npc.Calamity().newAI[2] < teslaOrbTelegraphDuration) && AIState == (float)Phase.TeslaOrbs)
{
float pulseRatio = (npc.Calamity().newAI[2] % (teslaOrbTelegraphDuration / 5f)) / (teslaOrbTelegraphDuration / 5f);
float pulseSize = MathHelper.Lerp(0.1f, 0.6f, (float)Math.Floor(npc.Calamity().newAI[2] / (teslaOrbTelegraphDuration / 5f)) / 4f);
float pulseOpacity = MathHelper.Clamp((float)Math.Floor(npc.Calamity().newAI[2] / (teslaOrbTelegraphDuration / 5f)) * 0.3f, 1f, 2f);
spriteBatch.Draw(texture, center, frame, Color.Aqua * MathHelper.Lerp(1f, 0f, pulseRatio) * pulseOpacity, npc.rotation, vector, npc.scale + pulseRatio * pulseSize, spriteEffects, 0f);
}
EnergyDrawer.DrawSet(npc.Center - npc.rotation.ToRotationVector2() * 35f);
//Back to normal
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
return false;
}
+60
View File
@@ -0,0 +1,60 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Particles
{
public class AresCannonChargeParticleSet : BaseParticleSet
{
public override int ParticleLifetime => 30;
public Color ParticleColor;
public float SpawnAreaCompactness;
public float MoveRotationOffset;
public AresCannonChargeParticleSet(int setLifetime, int particleSpawnRate, float spawnAreaCompactness, Color particleColor) :
base(setLifetime, particleSpawnRate)
{
ParticleColor = particleColor;
MoveRotationOffset = Main.rand.NextFloat(-0.36f, 0.36f);
SpawnAreaCompactness = spawnAreaCompactness;
}
//We'll use more than one here actually, so this doesnt matter that much
public override Particle SpawnParticle()
{
Vector2 originPoint = Main.rand.NextVector2CircularEdge(1f, 1f) * SpawnAreaCompactness;
return new ChargeUpLineVFX(originPoint, originPoint.ToRotation(), 0.2f, ParticleColor, ParticleLifetime, 0.6f, true);
}
public override 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;
//Spawn new particles if time remains
bool closeToDeath = LocalTimer >= SetLifetime - ParticleLifetime && SetLifetime > 0;
if (LocalTimer % ParticleSpawnRate == ParticleSpawnRate - 1 && !closeToDeath)
{
Particle particle = SpawnParticle();
Particles.Add(particle);
}
// Update and increment the time of all particles, alongside modifying their offset based on their velocity.
foreach (Particle particle in Particles)
{
particle.RelativeOffset += particle.Velocity;
particle.Time++;
particle.Update();
}
// Clear all expired particles.
Particles.RemoveAll(particle => particle.Time >= particle.Lifetime && particle.SetLifetime);
LocalTimer++;
}
}
}
+1 -1
View File
@@ -84,7 +84,7 @@ namespace CalamityMod.Particles
foreach (Particle particle in Particles.OrderBy(p => p.Time))
{
if (particle.UseCustomDraw)
particle.CustomDraw(Main.spriteBatch);
particle.CustomDraw(Main.spriteBatch, basePosition);
else
{
var tex = ModContent.GetTexture(particle.Texture);
+73
View File
@@ -0,0 +1,73 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Particles
{
public class ChargeUpLineVFX : Particle
{
public override string Texture => "CalamityMod/Particles/HalfLine";
public override bool UseAdditiveBlend => true;
public override bool UseCustomDraw => true;
public override bool SetLifetime => true;
public override bool Important => Telegraph;
public float BaseOpacity;
public float Opacity;
public float LineDirection;
public float LineLenght = 0f;
private Vector2 PrevOffset = Vector2.Zero;
public bool Telegraph; //Denotes if the line is used as an enemy telegraph. In that case, it'll be marked as important
public float FullFadeInPoint;
public float MinDistanceFromOrigin;
public ChargeUpLineVFX(Vector2 startPoint, float lineDirection, float thickness, Color color, int lifetime, float opacity = 1f, bool telegraph = true, float fullFadeInPoint = 0.5f, float minDistanceFromOrigin = 8f)
{
RelativeOffset = startPoint;
LineDirection = lineDirection + MathHelper.Pi;
Scale = thickness;
Color = color;
BaseOpacity = opacity;
Telegraph = telegraph;
FullFadeInPoint = fullFadeInPoint;
MinDistanceFromOrigin = minDistanceFromOrigin;
Velocity = Vector2.Zero;
Rotation = 0;
Lifetime = lifetime;
}
public override void Update()
{
Opacity = Time / (float)Lifetime > FullFadeInPoint ? BaseOpacity : (float)Math.Sin(Time / (FullFadeInPoint * Lifetime) * MathHelper.PiOver2) * BaseOpacity;
PrevOffset = Vector2.Lerp(PrevOffset, RelativeOffset, 0.1f);
RelativeOffset *= 0.8f;
LineLenght = (PrevOffset - RelativeOffset).Length();
if (RelativeOffset.Length() < MinDistanceFromOrigin)
RelativeOffset = LineDirection.ToRotationVector2() * MinDistanceFromOrigin;
}
public override void CustomDraw(SpriteBatch spriteBatch, Vector2 basePosition)
{
Texture2D tex = GeneralParticleHandler.GetTexture(Type);
Texture2D bloomTex = ModContent.GetTexture("CalamityMod/Particles/Light");
float rot = LineDirection + MathHelper.PiOver2;
Vector2 origin = new Vector2(tex.Width / 2f, tex.Height);
Vector2 scale = new Vector2(Scale, LineLenght / tex.Height);
Vector2 drawPosition = basePosition - Main.screenPosition + RelativeOffset;
Main.spriteBatch.Draw(tex, drawPosition, null, Color * Opacity * 0.8f, rot, origin, scale * 1.1f, SpriteEffects.None, 0f);
Main.spriteBatch.Draw(tex, drawPosition, null, Color.White * Opacity, rot, origin, scale, SpriteEffects.None, 0f);
Main.spriteBatch.Draw(bloomTex, drawPosition, null, Color * Opacity * 0.8f, 0f, bloomTex.Size() / 2f, Scale * 1.1f, SpriteEffects.None, 0f);
Main.spriteBatch.Draw(bloomTex, drawPosition, null, Color.White * Opacity, 0f, bloomTex.Size() / 2f, Scale, SpriteEffects.None, 0f);
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

+2
View File
@@ -60,6 +60,8 @@ namespace CalamityMod.Particles
/// 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) { }
public virtual void CustomDraw(SpriteBatch spriteBatch, Vector2 basePosition) { }
/// <summary>
/// Called for every update of the particle handler.
/// The particle's velocity gets automatically added to its position, and its time automatically increases.