Made Daedalus Golem Lightning epic

This commit is contained in:
Dominic committed 2020-10-16 17:54:45 -05:00
1 parent a7eacb4cb6
commit 07b6d97570
3 files changed
+77 -64

No files matched your search

+9 -2
View File
@@ -127,12 +127,14 @@ namespace CalamityMod.Projectiles.Summon
light.scale = Main.rand.NextFloat(1.2f, 1.45f);
light.noGravity = true;
}
else if (AttackTimer >= ChargedLaserAttackTime / 2 && AttackTimer <= ChargedLaserAttackTime / 2 + 30 && AttackTimer % 10 == 9)
else if (AttackTimer >= ChargedLaserAttackTime / 2 && AttackTimer <= ChargedLaserAttackTime / 2 + 60 && AttackTimer % 10 == 9)
{
Main.PlaySound(SoundID.Item122, ArmPosition);
if (Main.myPlayer == projectile.owner)
{
Vector2 initialVelocity = projectile.DirectionTo(potentialTarget.Center) * 3f;
Vector2 initialVelocity = projectile.DirectionTo(potentialTarget.Center) * 2f;
if (Main.rand.NextBool(2))
initialVelocity = initialVelocity.RotatedByRandom(0.4f);
float initialAngle = initialVelocity.ToRotation();
Projectile.NewProjectile(ArmPosition, initialVelocity, ModContent.ProjectileType<DaedalusLightning>(), projectile.damage, projectile.knockBack, projectile.owner, initialAngle, Main.rand.Next(100));
}
@@ -144,6 +146,11 @@ namespace CalamityMod.Projectiles.Summon
Projectile.NewProjectile(ArmPosition, initialVelocity, ModContent.ProjectileType<DaedalusPellet>(), projectile.damage, projectile.knockBack, projectile.owner);
}
}
else if (potentialTarget is null && AttackTimer != 0)
{
AttackTimer = 0;
projectile.netUpdate = true;
}
}
public void AdjustMinionDamage()
+24 -46
View File
@@ -2,6 +2,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
@@ -10,6 +11,8 @@ namespace CalamityMod.Projectiles.Summon
{
public class DaedalusLightning : ModProjectile
{
internal PrimitiveTrail LightningDrawer;
public const int MaximumBranchingIterations = 3;
public const float LightningTurnRandomnessFactor = 1f;
public ref float InitialVelocityAngle => ref projectile.ai[0];
@@ -23,7 +26,7 @@ namespace CalamityMod.Projectiles.Summon
{
DisplayName.SetDefault("Daedalus Lightning");
ProjectileID.Sets.MinionShot[projectile.type] = true;
ProjectileID.Sets.TrailCacheLength[projectile.type] = 20;
ProjectileID.Sets.TrailCacheLength[projectile.type] = 100;
ProjectileID.Sets.TrailingMode[projectile.type] = 1;
}
@@ -68,6 +71,10 @@ namespace CalamityMod.Projectiles.Summon
// which allows random turning to occur.
projectile.frameCounter++;
projectile.scale = (float)Math.Sin(MathHelper.Pi * projectile.timeLeft / (45f * (projectile.MaxUpdates - 1))) * 4f;
if (projectile.scale > 1f)
projectile.scale = 1f;
Lighting.AddLight(projectile.Center, Color.Pink.ToVector3());
if (projectile.frameCounter >= projectile.extraUpdates * 2)
{
@@ -97,8 +104,7 @@ namespace CalamityMod.Projectiles.Summon
// This mess of math basically encourages movement at the ends of an extraUpdate cycle,
// discourages super frequenent randomness as the accumulated X speed changes get larger,
// or if the original speed is quite large.
if (Math.Abs(potentialBaseDirection.X * (projectile.extraUpdates + 1) * 2f * originalSpeed + AccumulatedXMovementSpeeds) >
projectile.MaxUpdates * 2f * LightningTurnRandomnessFactor)
if (Math.Abs(potentialBaseDirection.X * (projectile.extraUpdates + 1) * 2f * originalSpeed + AccumulatedXMovementSpeeds) > projectile.MaxUpdates * LightningTurnRandomnessFactor)
{
canChangeLightningDirection = false;
}
@@ -120,53 +126,25 @@ namespace CalamityMod.Projectiles.Summon
}
}
#region Drawing
internal float WidthFunction(float completionRatio)
{
float baseWidth = MathHelper.Lerp(2f, 6f, (float)Math.Sin(MathHelper.Pi * 4f * completionRatio) * 0.5f + 0.5f) * projectile.scale;
return baseWidth * (float)Math.Sin(MathHelper.Pi * completionRatio);
}
internal Color ColorFunction(float completionRatio)
{
Color baseColor = Color.Lerp(Color.Pink, Color.HotPink, (float)Math.Sin(MathHelper.TwoPi * completionRatio + Main.GlobalTime * 4f) * 0.5f + 0.5f);
return Color.Lerp(baseColor, Color.Red, ((float)Math.Sin(MathHelper.Pi * completionRatio + Main.GlobalTime * 4f) * 0.5f + 0.5f) * 0.8f);
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Vector2 end = projectile.Center + Vector2.UnitY * projectile.gfxOffY - Main.screenPosition;
Texture2D lightningTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/Lasers/RedLightningTexture");
Vector2 scaleVector = new Vector2(projectile.scale) / 2f;
for (int i = 0; i < 3; i++)
{
// c_1 and f_1 are two somewhat ambiguous fields that are used by various methods
// in the DelegateMethods class. c_1 is used to represent the current color to be
// drawn while f_1 represents the opacity.
switch (i)
{
case 0:
scaleVector = new Vector2(projectile.scale) * 0.6f;
DelegateMethods.c_1 = Color.HotPink * 0.5f;
break;
case 1:
scaleVector = new Vector2(projectile.scale) * 0.4f;
DelegateMethods.c_1 = Color.Pink * 0.5f;
break;
case 2:
scaleVector = new Vector2(projectile.scale) * 0.2f;
DelegateMethods.c_1 = Color.White * 0.5f;
break;
}
DelegateMethods.f_1 = 1f;
if (LightningDrawer is null)
LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, false);
// Ignore zero oldPos indices.
// There are almost guaranteed to be currently unfilled instead of being
// legitimate positions.
for (int j = projectile.oldPos.Length - 1; j > 0; j--)
{
if (!(projectile.oldPos[j] == Vector2.Zero))
{
Vector2 start = projectile.oldPos[j] + projectile.Size * 0.5f + Vector2.UnitY * projectile.gfxOffY - Main.screenPosition;
Vector2 end2 = projectile.oldPos[j - 1] + projectile.Size * 0.5f + Vector2.UnitY * projectile.gfxOffY - Main.screenPosition;
Utils.DrawLaser(spriteBatch, lightningTexture, start, end2, scaleVector, DelegateMethods.LightningLaserDraw);
}
}
if (projectile.oldPos[0] != Vector2.Zero)
{
DelegateMethods.f_1 = 1f;
Vector2 start2 = projectile.oldPos[0] + projectile.Size * 0.5f + Vector2.UnitY * projectile.gfxOffY - Main.screenPosition;
Utils.DrawLaser(Main.spriteBatch, lightningTexture, start2, end, scaleVector, DelegateMethods.LightningLaserDraw);
}
}
LightningDrawer.Draw(projectile.oldPos.Where(oldPos => oldPos != Vector2.Zero), projectile.Size * 0.5f - Main.screenPosition, 300);
return false;
}
#endregion
}
}
+44 -16
View File
@@ -35,15 +35,21 @@ namespace CalamityMod
public VertexWidthFunction WidthFunction;
public VertexColorFunction ColorFunction;
// NOTE: Beziers can be laggy when a lot of control points are used, since our implementation
// uses a recursive Lerp that gets more computationally expensive the more original indices.
// n(n - 1)/2 linear interpolations to be precise, where n is the amount of original indices.
public bool UsesSmoothening;
public Effect EffectToUse;
public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, Effect specialShader = null)
public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, bool useSmoothening = true, Effect specialShader = null)
{
if (widthFunction is null || colorFunction is null)
throw new NullReferenceException($"In order to create a primitive trail, a non-null {(widthFunction is null ? "width" : "color")} function must be specified.");
WidthFunction = widthFunction;
ColorFunction = colorFunction;
UsesSmoothening = useSmoothening;
EffectToUse = specialShader ?? new BasicEffect(Main.instance.GraphicsDevice);
if (EffectToUse is BasicEffect)
{
@@ -83,22 +89,44 @@ namespace CalamityMod
{
if (EffectToUse is BasicEffect)
UpdateBasicEffect((BasicEffect)EffectToUse);
List<Vector2> originalControlPoints = new List<Vector2>();
// Don't smoothen the points unless explicitly told do so.
if (!UsesSmoothening)
{
List<Vector2> basePoints = originalPositions.Where(originalPosition => originalPosition != Vector2.Zero).ToList();
List<Vector2> endPoints = new List<Vector2>();
if (basePoints.Count < 3)
return endPoints;
// 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);
}
return endPoints;
}
List<Vector2> controlPoints = new List<Vector2>();
for (int i = 0; i < originalPositions.Count(); i++)
{
// Don't incorporate points that are zeroed out.
// They are almost certainly a result of incomplete oldPos arrays.
if (originalPositions.ElementAt(i) == Vector2.Zero)
continue;
originalControlPoints.Add(originalPositions.ElementAt(i) + generalOffset);
controlPoints.Add(originalPositions.ElementAt(i) + generalOffset);
}
BezierCurve bezierCurve = new BezierCurve(originalControlPoints.ToArray());
return originalControlPoints.Count <= 1 ? originalControlPoints : bezierCurve.GetPoints(totalTrailPoints);
BezierCurve bezierCurve = new BezierCurve(controlPoints.ToArray());
return controlPoints.Count <= 1 ? controlPoints : bezierCurve.GetPoints(totalTrailPoints);
}
public List<VertexPosition2DColor> GetVerticesFromTrailPoints(List<Vector2> trailPoints)
public VertexPosition2DColor[] GetVerticesFromTrailPoints(List<Vector2> trailPoints)
{
List<VertexPosition2DColor> vertices = new List<VertexPosition2DColor>();
VertexPosition2DColor[] vertices = new VertexPosition2DColor[trailPoints.Count * 6];
for (int i = 0; i < trailPoints.Count - 1; i++)
{
float completionRatio = i / (float)trailPoints.Count;
@@ -122,14 +150,14 @@ namespace CalamityMod
// What this is doing, at its core, is defining a rectangle based on two triangles.
// These triangles are defined based on the width of the strip at that point.
// These rectangles combined are what make the trail itself.
vertices.Add(new VertexPosition2DColor(firstUp, vertexColor));
vertices.Add(new VertexPosition2DColor(secondUp, vertexColor));
vertices.Add(new VertexPosition2DColor(firstDown, vertexColor));
// The resulting rectangles combined are what make the trail itself.
vertices[i * 6] = new VertexPosition2DColor(firstUp, vertexColor);
vertices[i * 6 + 1] = new VertexPosition2DColor(secondUp, vertexColor);
vertices[i * 6 + 2] = new VertexPosition2DColor(firstDown, vertexColor);
vertices.Add(new VertexPosition2DColor(secondUp, vertexColor));
vertices.Add(new VertexPosition2DColor(secondDown, vertexColor));
vertices.Add(new VertexPosition2DColor(firstDown, vertexColor));
vertices[i * 6 + 3] = new VertexPosition2DColor(secondUp, vertexColor);
vertices[i * 6 + 4] = new VertexPosition2DColor(secondDown, vertexColor);
vertices[i * 6 + 5] = new VertexPosition2DColor(firstDown, vertexColor);
}
return vertices;
}
@@ -144,7 +172,7 @@ namespace CalamityMod
if (trailPoints.Count <= 1)
return;
List<VertexPosition2DColor> vertices = GetVerticesFromTrailPoints(trailPoints);
VertexPosition2DColor[] vertices = GetVerticesFromTrailPoints(trailPoints);
foreach (var pass in EffectToUse.CurrentTechnique.Passes)
{
@@ -153,7 +181,7 @@ namespace CalamityMod
// The division by 3 here is because, vertices is a list of vertices.
// That parameter, however, wants the amount of primitives (in this case triangles), it should draw.
// Getting the amount of triangles in this case is simply a matter of dividing the total vertices by 3.
Main.instance.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices.ToArray(), 0, vertices.Count / 3);
Main.instance.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3);
}
}
}