Artemis and Apollo charge visual effects

This commit is contained in:
DominicKarma committed 2021-09-28 19:56:57 -05:00
1 parent b83a45502b
commit eec2220400
8 files changed
+370 -146

No files matched your search

+3
View File
@@ -21,6 +21,7 @@ namespace CalamityMod.Effects
public static Effect ScarletDevilShader;
public static Effect BordernadoFireShader;
public static Effect PrismCrystalShader;
public static Effect ImpFlameTrailShader;
public static Effect SCalShieldShader;
public static void LoadShaders()
@@ -41,6 +42,7 @@ namespace CalamityMod.Effects
FadedUVMapStreakShader = CalamityMod.Instance.GetEffect("Effects/FadedUVMapStreak");
FlameStreakShader = CalamityMod.Instance.GetEffect("Effects/Flame");
FadingSolidTrailShader = CalamityMod.Instance.GetEffect("Effects/FadingSolidTrail");
ImpFlameTrailShader = CalamityMod.Instance.GetEffect("Effects/ImpFlameTrail");
SCalShieldShader = CalamityMod.Instance.GetEffect("Effects/SupremeShieldShader");
Filters.Scene["CalamityMod:Astral"] = new Filter(new AstralScreenShaderData(new Ref<Effect>(AstralFogShader), "AstralPass").UseColor(0.18f, 0.08f, 0.24f), EffectPriority.VeryHigh);
@@ -59,6 +61,7 @@ namespace CalamityMod.Effects
GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"] = new MiscShaderData(new Ref<Effect>(ScarletDevilShader), "TrailPass");
GameShaders.Misc["CalamityMod:Bordernado"] = new MiscShaderData(new Ref<Effect>(BordernadoFireShader), "TrailPass");
GameShaders.Misc["CalamityMod:PrismaticStreak"] = new MiscShaderData(new Ref<Effect>(PrismCrystalShader), "TrailPass");
GameShaders.Misc["CalamityMod:ImpFlameTrail"] = new MiscShaderData(new Ref<Effect>(ImpFlameTrailShader), "TrailPass");
GameShaders.Misc["CalamityMod:SupremeShield"] = new MiscShaderData(new Ref<Effect>(SCalShieldShader), "ShieldPass");
}
}
BIN
View File
Binary file not shown.
Binary file not shown.
+136 -29
View File
@@ -13,6 +13,7 @@ using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Graphics.Shaders;
namespace CalamityMod.NPCs.ExoMechs.Apollo
{
@@ -100,6 +101,13 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo
private const int maxCharges = 4;
public Vector2[] chargeLocations = new Vector2[maxCharges] { default, default, default, default };
// Intensity of flash effects during the charge combo
public float ChargeComboFlash;
// Primitive trail drawers for thrusters when charging
public PrimitiveTrail ChargeFlameTrail = null;
public PrimitiveTrail ChargeFlameTrailBig = null;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("XS-03 Apollo");
@@ -485,6 +493,14 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo
destination.Y += npc.localAI[1];
}
// Cause the charge visual effects to begin while performing or preparing for a combo
if (AIState == (float)Phase.LineUpChargeCombo || AIState == (float)Phase.ChargeCombo)
ChargeComboFlash = MathHelper.Clamp(ChargeComboFlash + 0.08f, 0f, 1f);
// And have them go away afterwards
else
ChargeComboFlash = MathHelper.Clamp(ChargeComboFlash - 0.1f, 0f, 1f);
// Destination variables
Vector2 distanceFromDestination = destination - npc.Center;
Vector2 desiredVelocity = Vector2.Normalize(distanceFromDestination) * baseVelocity;
@@ -828,6 +844,10 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo
{
// Save the charge locations and create telegraph beams
int type = ModContent.ProjectileType<ApolloChargeTelegraph>();
// Play a charge sound
Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LaserCannon"), npc.Center);
for (int i = 0; i < maxCharges; i++)
{
if (chargeLocations[i] == default)
@@ -849,22 +869,20 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo
default:
break;
}
// Draw telegraph beams
if (i > 0)
{
if (Main.netMode != NetmodeID.MultiplayerClient)
{
if (i == 1)
Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LaserCannon"), npc.Center);
Vector2 laserVelocity = Vector2.Normalize(chargeLocations[i] - chargeLocations[i - 1]);
Projectile.NewProjectile(chargeLocations[i - 1], laserVelocity, type, 0, 0f, Main.myPlayer, 0f, npc.whoAmI);
}
}
}
}
// Draw telegraph beams
if (Main.netMode != NetmodeID.MultiplayerClient)
{
int telegraph = Projectile.NewProjectile(chargeLocations[0], Vector2.Zero, type, 0, 0f, Main.myPlayer, 0f, npc.whoAmI);
if (Main.projectile.IndexInRange(telegraph))
{
Main.projectile[telegraph].ModProjectile<ApolloChargeTelegraph>().ChargePositions = chargeLocations;
Main.projectile[telegraph].netUpdate = true;
}
}
// Don't move
npc.velocity = Vector2.Zero;
@@ -915,6 +933,7 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo
calamityGlobalNPC.newAI[2] = 0f;
for (int i = 0; i < maxCharges; i++)
chargeLocations[i] = default;
ChargeComboFlash = 0f;
npc.TargetClosest();
}
@@ -1077,34 +1096,91 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo
}
}
public float FlameTrailWidthFunction(float completionRatio) => MathHelper.SmoothStep(21f, 8f, completionRatio) * ChargeComboFlash;
public float FlameTrailWidthFunctionBig(float completionRatio) => MathHelper.SmoothStep(34f, 12f, completionRatio) * ChargeComboFlash;
public Color FlameTrailColorFunction(float completionRatio)
{
float trailOpacity = Utils.InverseLerp(0.8f, 0.27f, completionRatio, true) * Utils.InverseLerp(0f, 0.067f, completionRatio, true);
Color startingColor = Color.Lerp(Color.White, Color.Cyan, 0.27f);
Color middleColor = Color.Lerp(Color.Orange, Color.ForestGreen, 0.74f);
Color endColor = Color.Lime;
return CalamityUtils.MulticolorLerp(completionRatio, startingColor, middleColor, endColor) * ChargeComboFlash * trailOpacity;
}
public Color FlameTrailColorFunctionBig(float completionRatio)
{
float trailOpacity = Utils.InverseLerp(0.8f, 0.27f, completionRatio, true) * Utils.InverseLerp(0f, 0.067f, completionRatio, true) * 0.56f;
Color startingColor = Color.Lerp(Color.White, Color.Cyan, 0.25f);
Color middleColor = Color.Lerp(Color.Blue, Color.White, 0.35f);
Color endColor = Color.Lerp(Color.DarkBlue, Color.White, 0.47f);
Color color = CalamityUtils.MulticolorLerp(completionRatio, startingColor, middleColor, endColor) * ChargeComboFlash * trailOpacity;
color.A = 0;
return color;
}
public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor)
{
// Declare the trail drawers if they have yet to be defined.
if (ChargeFlameTrail is null)
ChargeFlameTrail = new PrimitiveTrail(FlameTrailWidthFunction, FlameTrailColorFunction, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
if (ChargeFlameTrailBig is null)
ChargeFlameTrailBig = new PrimitiveTrail(FlameTrailWidthFunctionBig, FlameTrailColorFunctionBig, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
// Prepare the flame trail shader with its map texture.
GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak"));
int numAfterimages = 5;
Texture2D texture = Main.npcTexture[npc.type];
Rectangle frame = new Rectangle(npc.width * frameX, npc.height * frameY, npc.width, npc.height);
Vector2 vector = new Vector2(npc.width / 2, npc.height / 2);
Vector2 center = npc.Center - Main.screenPosition;
Color afterimageBaseColor = Color.White;
int numAfterimages = 5;
if (CalamityConfig.Instance.Afterimages)
// Draws a single instance of a regular, non-glowmask based Artemis.
// This is created to allow easy duplicate of them when drawing the charge.
void drawInstance(Vector2 drawOffset, Color baseColor)
{
for (int i = 1; i < numAfterimages; i += 2)
if (CalamityConfig.Instance.Afterimages)
{
Color afterimageColor = drawColor;
afterimageColor = Color.Lerp(afterimageColor, afterimageBaseColor, 0.5f);
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 / Main.npcFrameCount[npc.type]) * npc.scale / 2f;
afterimageCenter += vector * npc.scale + new Vector2(0f, npc.gfxOffY);
spriteBatch.Draw(texture, afterimageCenter, npc.frame, afterimageColor, npc.rotation, vector, npc.scale, SpriteEffects.None, 0f);
for (int i = 1; i < numAfterimages; i += 2)
{
Color afterimageColor = baseColor;
afterimageColor = Color.Lerp(afterimageColor, afterimageBaseColor, 0.5f);
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 / Main.npcFrameCount[npc.type]) * npc.scale / 2f;
afterimageCenter += vector * npc.scale + new Vector2(0f, npc.gfxOffY);
afterimageCenter += drawOffset;
spriteBatch.Draw(texture, afterimageCenter, npc.frame, afterimageColor, npc.rotation, vector, npc.scale, SpriteEffects.None, 0f);
}
}
spriteBatch.Draw(texture, center + drawOffset, frame, npc.GetAlpha(baseColor), npc.rotation, vector, npc.scale, SpriteEffects.None, 0f);
}
int instanceCount = (int)MathHelper.Lerp(1f, 15f, ChargeComboFlash);
Color baseInstanceColor = Color.Lerp(drawColor, Color.White, ChargeComboFlash);
baseInstanceColor.A = (byte)(int)(255f - ChargeComboFlash * 255f);
spriteBatch.EnterShaderRegion();
drawInstance(Vector2.Zero, baseInstanceColor);
if (instanceCount > 1)
{
baseInstanceColor *= 0.04f;
float backAfterimageOffset = MathHelper.SmoothStep(0f, 2f, ChargeComboFlash);
for (int i = 0; i < instanceCount; i++)
{
Vector2 drawOffset = (MathHelper.TwoPi * i / instanceCount + Main.GlobalTime * 0.8f).ToRotationVector2() * backAfterimageOffset;
drawInstance(drawOffset, baseInstanceColor);
}
}
Vector2 center = npc.Center - Main.screenPosition;
spriteBatch.Draw(texture, center, frame, npc.GetAlpha(drawColor), npc.rotation, vector, npc.scale, SpriteEffects.None, 0f);
texture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Apollo/ApolloGlow");
if (CalamityConfig.Instance.Afterimages)
{
for (int i = 1; i < numAfterimages; i += 2)
@@ -1122,6 +1198,37 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo
spriteBatch.Draw(texture, center, frame, Color.White * npc.Opacity, npc.rotation, vector, npc.scale, SpriteEffects.None, 0f);
spriteBatch.ExitShaderRegion();
// Draw a flame trail on the thrusters if needed. This happens during charges.
if (ChargeComboFlash > 0f)
{
for (int direction = -1; direction <= 1; direction++)
{
Vector2 baseDrawOffset = new Vector2(0f, direction == 0f ? 18f : 60f).RotatedBy(npc.rotation);
baseDrawOffset += new Vector2(direction * 64f, 0f).RotatedBy(npc.rotation);
float backFlameLength = direction == 0f ? 700f : 190f;
Vector2 drawStart = npc.Center + baseDrawOffset;
Vector2 drawEnd = drawStart - (npc.rotation - MathHelper.PiOver2).ToRotationVector2() * ChargeComboFlash * backFlameLength;
Vector2[] drawPositions = new Vector2[]
{
drawStart,
drawEnd
};
if (direction == 0)
{
for (int i = 0; i < 4; i++)
{
Vector2 drawOffset = (MathHelper.TwoPi * i / 4f).ToRotationVector2() * 8f;
ChargeFlameTrailBig.Draw(drawPositions, drawOffset - Main.screenPosition, 70);
}
}
else
ChargeFlameTrail.Draw(drawPositions, -Main.screenPosition, 70);
}
}
return false;
}
+125 -16
View File
@@ -10,6 +10,7 @@ using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
@@ -110,6 +111,13 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis
// The point to spin around
private Vector2 spinningPoint = default;
// Intensity of flash effects during the charge combo
public float ChargeFlash;
// Primitive trail drawers for thrusters when charging
public PrimitiveTrail ChargeFlameTrail = null;
public PrimitiveTrail ChargeFlameTrailBig = null;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("XS-01 Artemis");
@@ -507,6 +515,9 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis
frameY = 3;
}
// Variable for charge flash. Changed in parts of the AI below
bool shouldDoChargeFlash = false;
// Passive and Immune phases
switch ((int)SecondaryAIState)
{
@@ -751,8 +762,11 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis
else
{
// Draw a large laser telegraph for the charge
if (!phase2 && calamityGlobalNPC.newAI[3] == attackPhaseGateValue + 2f)
if (!phase2 && calamityGlobalNPC.newAI[3] == attackPhaseGateValue + 5f)
{
// And allow the charge flash effect
shouldDoChargeFlash = true;
if (Main.netMode != NetmodeID.MultiplayerClient)
{
int type = ModContent.ProjectileType<ArtemisChargeTelegraph>();
@@ -788,6 +802,9 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis
// Charge
case (int)Phase.Charge:
// Allow the charge flash to happen
shouldDoChargeFlash = true;
// Reset phase and variables
calamityGlobalNPC.newAI[2] += 1f;
if (calamityGlobalNPC.newAI[2] >= chargeDuration)
@@ -1008,6 +1025,9 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis
break;
}
// Update the charge flash variable
ChargeFlash = MathHelper.Clamp(ChargeFlash + shouldDoChargeFlash.ToDirectionInt() * 0.08f, 0f, 1f);
}
public override bool CanHitPlayer(Player target, ref int cooldownSlot)
@@ -1118,34 +1138,91 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis
}
}
public float FlameTrailWidthFunction(float completionRatio) => MathHelper.SmoothStep(21f, 8f, completionRatio) * ChargeFlash;
public float FlameTrailWidthFunctionBig(float completionRatio) => MathHelper.SmoothStep(34f, 12f, completionRatio) * ChargeFlash;
public Color FlameTrailColorFunction(float completionRatio)
{
float trailOpacity = Utils.InverseLerp(0.8f, 0.27f, completionRatio, true) * Utils.InverseLerp(0f, 0.067f, completionRatio, true);
Color startingColor = Color.Lerp(Color.White, Color.Cyan, 0.27f);
Color middleColor = Color.Lerp(Color.Orange, Color.Yellow, 0.31f);
Color endColor = Color.OrangeRed;
return CalamityUtils.MulticolorLerp(completionRatio, startingColor, middleColor, endColor) * ChargeFlash * trailOpacity;
}
public Color FlameTrailColorFunctionBig(float completionRatio)
{
float trailOpacity = Utils.InverseLerp(0.8f, 0.27f, completionRatio, true) * Utils.InverseLerp(0f, 0.067f, completionRatio, true) * 0.56f;
Color startingColor = Color.Lerp(Color.White, Color.Cyan, 0.25f);
Color middleColor = Color.Lerp(Color.Blue, Color.White, 0.35f);
Color endColor = Color.Lerp(Color.DarkBlue, Color.White, 0.47f);
Color color = CalamityUtils.MulticolorLerp(completionRatio, startingColor, middleColor, endColor) * ChargeFlash * trailOpacity;
color.A = 0;
return color;
}
public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor)
{
// Declare the trail drawers if they have yet to be defined.
if (ChargeFlameTrail is null)
ChargeFlameTrail = new PrimitiveTrail(FlameTrailWidthFunction, FlameTrailColorFunction, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
if (ChargeFlameTrailBig is null)
ChargeFlameTrailBig = new PrimitiveTrail(FlameTrailWidthFunctionBig, FlameTrailColorFunctionBig, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]);
// Prepare the flame trail shader with its map texture.
GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak"));
int numAfterimages = 5;
Texture2D texture = Main.npcTexture[npc.type];
Rectangle frame = new Rectangle(npc.width * frameX, npc.height * frameY, npc.width, npc.height);
Vector2 vector = new Vector2(npc.width / 2, npc.height / 2);
Vector2 center = npc.Center - Main.screenPosition;
Color afterimageBaseColor = Color.White;
int numAfterimages = 5;
if (CalamityConfig.Instance.Afterimages)
// Draws a single instance of a regular, non-glowmask based Artemis.
// This is created to allow easy duplicate of them when drawing the charge.
void drawInstance(Vector2 drawOffset, Color baseColor)
{
for (int i = 1; i < numAfterimages; i += 2)
if (CalamityConfig.Instance.Afterimages)
{
Color afterimageColor = drawColor;
afterimageColor = Color.Lerp(afterimageColor, afterimageBaseColor, 0.5f);
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 / Main.npcFrameCount[npc.type]) * npc.scale / 2f;
afterimageCenter += vector * npc.scale + new Vector2(0f, npc.gfxOffY);
spriteBatch.Draw(texture, afterimageCenter, npc.frame, afterimageColor, npc.rotation, vector, npc.scale, SpriteEffects.None, 0f);
for (int i = 1; i < numAfterimages; i += 2)
{
Color afterimageColor = baseColor;
afterimageColor = Color.Lerp(afterimageColor, afterimageBaseColor, 0.5f);
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 / Main.npcFrameCount[npc.type]) * npc.scale / 2f;
afterimageCenter += vector * npc.scale + new Vector2(0f, npc.gfxOffY);
afterimageCenter += drawOffset;
spriteBatch.Draw(texture, afterimageCenter, npc.frame, afterimageColor, npc.rotation, vector, npc.scale, SpriteEffects.None, 0f);
}
}
spriteBatch.Draw(texture, center + drawOffset, frame, npc.GetAlpha(baseColor), npc.rotation, vector, npc.scale, SpriteEffects.None, 0f);
}
int instanceCount = (int)MathHelper.Lerp(1f, 15f, ChargeFlash);
Color baseInstanceColor = Color.Lerp(drawColor, Color.White, ChargeFlash);
baseInstanceColor.A = (byte)(int)(255f - ChargeFlash * 255f);
spriteBatch.EnterShaderRegion();
drawInstance(Vector2.Zero, baseInstanceColor);
if (instanceCount > 1)
{
baseInstanceColor *= 0.04f;
float backAfterimageOffset = MathHelper.SmoothStep(0f, 2f, ChargeFlash);
for (int i = 0; i < instanceCount; i++)
{
Vector2 drawOffset = (MathHelper.TwoPi * i / instanceCount + Main.GlobalTime * 0.8f).ToRotationVector2() * backAfterimageOffset;
drawInstance(drawOffset, baseInstanceColor);
}
}
Vector2 center = npc.Center - Main.screenPosition;
spriteBatch.Draw(texture, center, frame, npc.GetAlpha(drawColor), npc.rotation, vector, npc.scale, SpriteEffects.None, 0f);
texture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Artemis/ArtemisGlow");
if (CalamityConfig.Instance.Afterimages)
{
for (int i = 1; i < numAfterimages; i += 2)
@@ -1163,6 +1240,38 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis
spriteBatch.Draw(texture, center, frame, Color.White * npc.Opacity, npc.rotation, vector, npc.scale, SpriteEffects.None, 0f);
spriteBatch.ExitShaderRegion();
// Draw a flame trail on the thrusters if needed. This happens during charges.
if (ChargeFlash > 0f)
{
for (int direction = -1; direction <= 1; direction++)
{
Vector2 baseDrawOffset = new Vector2(0f, direction == 0f ? 18f : 60f).RotatedBy(npc.rotation);
baseDrawOffset += new Vector2(direction * 64f, 0f).RotatedBy(npc.rotation);
float backFlameLength = direction == 0f ? 700f : 190f;
Vector2 drawStart = npc.Center + baseDrawOffset;
Vector2 drawEnd = drawStart - (npc.rotation - MathHelper.PiOver2).ToRotationVector2() * ChargeFlash * backFlameLength;
Vector2[] drawPositions = new Vector2[]
{
drawStart,
drawEnd
};
if (direction == 0)
{
for (int i = 0; i < 4; i++)
{
Vector2 drawOffset = (MathHelper.TwoPi * i / 4f).ToRotationVector2() * 8f;
ChargeFlameTrailBig.Draw(drawPositions, drawOffset - Main.screenPosition, 70);
}
}
else
ChargeFlameTrail.Draw(drawPositions, -Main.screenPosition, 70);
}
}
return false;
}
+43 -36
View File
@@ -2,23 +2,19 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Boss
{
public class ApolloChargeTelegraph : ModProjectile
{
public Vector2[] ChargePositions = new Vector2[1];
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public float TelegraphDelay
{
get => projectile.ai[0];
set => projectile.ai[0] = value;
}
public NPC ThingToAttachTo => Main.npc.IndexInRange((int)projectile.ai[1]) ? Main.npc[(int)projectile.ai[1]] : null;
public Vector2 OldVelocity;
public PrimitiveTrail TelegraphDrawer = null;
public const float TelegraphTotalTime = 30f;
public const float TelegraphFadeTime = 15f;
public const float TelegraphWidth = 943.39811f; // a squared plus b squared equals c squared, dumbass
@@ -42,13 +38,17 @@ namespace CalamityMod.Projectiles.Boss
public override void SendExtraAI(BinaryWriter writer)
{
writer.WriteVector2(OldVelocity);
writer.Write(ChargePositions.Length);
for (int i = 0; i < ChargePositions.Length; i++)
writer.WriteVector2(ChargePositions[i]);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
OldVelocity = reader.ReadVector2();
}
ChargePositions = new Vector2[reader.ReadInt32()];
for (int i = 0; i < ChargePositions.Length; i++)
ChargePositions[i] = reader.ReadVector2();
}
public override void AI()
{
@@ -66,16 +66,8 @@ namespace CalamityMod.Projectiles.Boss
return;
}
// Be sure to save the velocity the projectile started with.
if (OldVelocity == Vector2.Zero)
{
OldVelocity = projectile.velocity;
projectile.velocity = Vector2.Zero;
projectile.netUpdate = true;
projectile.rotation = OldVelocity.ToRotation() + MathHelper.PiOver2;
}
TelegraphDelay++;
// Determine opacity
projectile.Opacity = Utils.InverseLerp(0f, 6f, projectile.timeLeft, true) * Utils.InverseLerp(30f, 24f, projectile.timeLeft, true);
}
public override Color? GetAlpha(Color lightColor)
@@ -83,28 +75,43 @@ namespace CalamityMod.Projectiles.Boss
return new Color(255, 255, 255, projectile.alpha);
}
public Color TelegraphPrimitiveColor(float completionRatio)
{
float opacity = MathHelper.Lerp(0.18f, 0.43f, projectile.Opacity);
opacity *= CalamityUtils.Convert01To010(completionRatio);
opacity *= (float)System.Math.Pow(MathHelper.Lerp(0.9f, 0.125f, projectile.ai[0] / (ChargePositions.Length - 1f)), 2D);
if (completionRatio > 0.95f)
opacity = 0.0000001f;
return Color.Green * opacity;
}
public float TelegraphPrimitiveWidth(float completionRatio)
{
return projectile.Opacity * 15f;
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Texture2D laserTelegraph = ModContent.GetTexture("CalamityMod/ExtraTextures/LaserWallTelegraphBeam");
float yScale = 25f;
if (TelegraphDelay < TelegraphFadeTime)
yScale = MathHelper.Lerp(0f, 25f, TelegraphDelay / 15f);
if (TelegraphDelay > TelegraphTotalTime - TelegraphFadeTime)
yScale = MathHelper.Lerp(25f, 0f, (TelegraphDelay - (TelegraphTotalTime - TelegraphFadeTime)) / 15f);
if (TelegraphDrawer is null)
TelegraphDrawer = new PrimitiveTrail(TelegraphPrimitiveWidth, TelegraphPrimitiveColor, PrimitiveTrail.RigidPointRetreivalFunction, GameShaders.Misc["CalamityMod:Flame"]);
Vector2 scaleInner = new Vector2(TelegraphWidth / laserTelegraph.Width, yScale);
Vector2 origin = laserTelegraph.Size() * new Vector2(0f, 0.5f);
Vector2 scaleOuter = scaleInner * new Vector2(1f, 1.6f);
GameShaders.Misc["CalamityMod:Flame"].UseImage("Images/Misc/Perlin");
GameShaders.Misc["CalamityMod:Flame"].UseSaturation(0.41f);
Color colorOuter = Color.Lerp(Color.Green, Color.Lime, TelegraphDelay / TelegraphTotalTime * 2f % 1f); // Iterate through green and lime once and then flash.
Color colorInner = Color.Lerp(colorOuter, Color.White, 0.75f);
for (int i = ChargePositions.Length - 2; i >= 0; i--)
{
Vector2[] positions = new Vector2[2]
{
ChargePositions[i],
ChargePositions[i + 1]
};
colorOuter *= 0.7f;
colorInner *= 0.7f;
spriteBatch.Draw(laserTelegraph, projectile.Center - Main.screenPosition, null, colorInner, OldVelocity.ToRotation(), origin, scaleInner, SpriteEffects.None, 0f);
spriteBatch.Draw(laserTelegraph, projectile.Center - Main.screenPosition, null, colorOuter, OldVelocity.ToRotation(), origin, scaleOuter, SpriteEffects.None, 0f);
// Stand-in variable used to differentiate between the beams.
// It is not used anywhere else.
projectile.ai[0] = i;
TelegraphDrawer.Draw(positions, projectile.Size * 0.5f - Main.screenPosition, 55);
}
return false;
}
}
+50 -57
View File
@@ -1,26 +1,21 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using Terraria;
using Terraria.Graphics.Shaders;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Boss
{
public class ArtemisChargeTelegraph : ModProjectile
{
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
public float TelegraphDelay
{
get => projectile.ai[0];
set => projectile.ai[0] = value;
}
public NPC ThingToAttachTo => Main.npc.IndexInRange((int)projectile.ai[1]) ? Main.npc[(int)projectile.ai[1]] : null;
public NPC ThingToAttachTo => Main.npc.IndexInRange((int)projectile.ai[1]) ? Main.npc[(int)projectile.ai[1]] : null;
public Vector2 OldVelocity;
public const float TelegraphTotalTime = 30f;
public const float TelegraphFadeTime = 15f;
public Vector2 OldVelocity;
public PrimitiveTrail TelegraphDrawer = null;
public const float TelegraphWidth = 2000f;
public override void SetStaticDefaults()
@@ -30,7 +25,7 @@ namespace CalamityMod.Projectiles.Boss
public override void SetDefaults()
{
projectile.width = 10;
projectile.width = 10;
projectile.height = 10;
projectile.hostile = true;
projectile.ignoreWater = true;
@@ -38,19 +33,19 @@ namespace CalamityMod.Projectiles.Boss
projectile.alpha = 255;
projectile.penetrate = -1;
projectile.timeLeft = 30;
}
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.WriteVector2(OldVelocity);
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.WriteVector2(OldVelocity);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
OldVelocity = reader.ReadVector2();
}
public override void ReceiveExtraAI(BinaryReader reader)
{
OldVelocity = reader.ReadVector2();
}
public override void AI()
public override void AI()
{
// Determine the relative opacities for each player based on their distance.
if (projectile.localAI[0] == 0f)
@@ -59,26 +54,18 @@ namespace CalamityMod.Projectiles.Boss
projectile.netUpdate = true;
}
// Die if the thing to attach to disappears.
if (ThingToAttachTo is null || !ThingToAttachTo.active)
{
projectile.Kill();
return;
}
// Set start of telegraph to the npc center.
projectile.Center = ThingToAttachTo.Center + Vector2.Normalize(OldVelocity) * 50f;
// Be sure to save the velocity the projectile started with.
if (OldVelocity == Vector2.Zero)
// Die if the thing to attach to disappears.
if (ThingToAttachTo is null || !ThingToAttachTo.active)
{
OldVelocity = projectile.velocity;
projectile.velocity = Vector2.Zero;
projectile.netUpdate = true;
projectile.rotation = OldVelocity.ToRotation() + MathHelper.PiOver2;
projectile.Kill();
return;
}
TelegraphDelay++;
// Set start of telegraph to the npc center.
projectile.Center = ThingToAttachTo.Center + projectile.velocity * 50f;
// Determine opacity
projectile.Opacity = Utils.InverseLerp(0f, 8f, projectile.timeLeft, true);
}
public override Color? GetAlpha(Color lightColor)
@@ -86,28 +73,34 @@ namespace CalamityMod.Projectiles.Boss
return new Color(255, 255, 255, projectile.alpha);
}
public Color TelegraphPrimitiveColor(float completionRatio)
{
float colorInterpolant = (completionRatio * 1.2f + Main.GlobalTime * 0.26f) % 1f;
float opacity = MathHelper.Lerp(0.2f, 0.425f, projectile.Opacity) * Utils.InverseLerp(30f, 24f, projectile.timeLeft, true);
return CalamityUtils.MulticolorLerp(colorInterpolant, Color.Orange, Color.Red, Color.Crimson, Color.Red) * opacity;
}
public float TelegraphPrimitiveWidth(float completionRatio)
{
// Used to determine the degree to which the ends of the telegraph should smoothen away.
float endSmoothenFactor = Utils.InverseLerp(1f, 0.995f, completionRatio, true);
return endSmoothenFactor * projectile.Opacity * 22f;
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Texture2D laserTelegraph = ModContent.GetTexture("CalamityMod/ExtraTextures/LaserWallTelegraphBeam");
float yScale = 25f;
if (TelegraphDelay < TelegraphFadeTime)
yScale = MathHelper.Lerp(0f, 25f, TelegraphDelay / 15f);
if (TelegraphDelay > TelegraphTotalTime - TelegraphFadeTime)
yScale = MathHelper.Lerp(25f, 0f, (TelegraphDelay - (TelegraphTotalTime - TelegraphFadeTime)) / 15f);
if (TelegraphDrawer is null)
TelegraphDrawer = new PrimitiveTrail(TelegraphPrimitiveWidth, TelegraphPrimitiveColor, specialShader: GameShaders.Misc["CalamityMod:Flame"]);
Vector2 scaleInner = new Vector2(TelegraphWidth / laserTelegraph.Width, yScale);
Vector2 origin = laserTelegraph.Size() * new Vector2(0f, 0.5f);
Vector2 scaleOuter = scaleInner * new Vector2(1f, 1.6f);
Color colorOuter = Color.Lerp(Color.Red, Color.Crimson, TelegraphDelay / TelegraphTotalTime * 2f % 1f); // Iterate through crimson and red once and then flash.
Color colorInner = Color.Lerp(colorOuter, Color.White, 0.75f);
colorOuter *= 0.7f;
colorInner *= 0.7f;
spriteBatch.Draw(laserTelegraph, projectile.Center - Main.screenPosition, null, colorInner, OldVelocity.ToRotation(), origin, scaleInner, SpriteEffects.None, 0f);
spriteBatch.Draw(laserTelegraph, projectile.Center - Main.screenPosition, null, colorOuter, OldVelocity.ToRotation(), origin, scaleOuter, SpriteEffects.None, 0f);
GameShaders.Misc["CalamityMod:Flame"].UseImage("Images/Misc/Perlin");
GameShaders.Misc["CalamityMod:Flame"].UseSaturation(0.28f);
Vector2[] drawPositions = new Vector2[]
{
projectile.Center,
projectile.Center + projectile.velocity.SafeNormalize(Vector2.UnitY) * TelegraphWidth
};
TelegraphDrawer.Draw(drawPositions, projectile.Size * 0.5f - Main.screenPosition, 87);
return false;
}
}
+13 -8
View File
@@ -105,18 +105,23 @@ namespace CalamityMod
List<Vector2> basePoints = originalPositions.Where(originalPosition => originalPosition != Vector2.Zero).ToList();
List<Vector2> endPoints = new List<Vector2>();
if (basePoints.Count < 3)
return endPoints;
if (basePoints.Count < 2)
{
for (int i = 0; i < basePoints.Count; i++)
basePoints[i] += generalOffset;
return basePoints;
}
// Remap the original positions across a certain length.
for (int i = 0; i < totalTrailPoints; i++)
{
float completionRatio = i / (float)totalTrailPoints;
int currentColorIndex = (int)(completionRatio * (basePoints.Count - 1));
Vector2 currentColor = basePoints[currentColorIndex];
Vector2 nextColor = basePoints[(currentColorIndex + 1) % basePoints.Count];
endPoints.Add(Vector2.Lerp(currentColor, nextColor, completionRatio * (basePoints.Count - 1) % 0.999f) + generalOffset);
float completionRatio = i / (float)(totalTrailPoints - 1f);
int currentIndex = (int)(completionRatio * (basePoints.Count - 1));
Vector2 currentPoint = basePoints[currentIndex];
Vector2 nextPoint = basePoints[(currentIndex + 1) % basePoints.Count];
endPoints.Add(Vector2.Lerp(currentPoint, nextPoint, completionRatio * (basePoints.Count - 1) % 0.99999f) + generalOffset);
}
endPoints.Add(basePoints.Last() + generalOffset);
return endPoints;
}
@@ -247,7 +252,7 @@ namespace CalamityMod
List<Vector2> trailPoints = TrailPointFunction(originalPositions, generalOffset, totalTrailPoints, originalRotations);
// A trail with only one point or less has nothing to connect to, and therefore, can't make a trail.
if (trailPoints.Count <= 2)
if (trailPoints.Count < 2)
return;
// If the trail points have any NaN positions, don't draw anything.