Finished the Photon Ripper

Also made some primitive drawing adjustments/fixes
This commit is contained in:
Dominic committed 2021-02-20 14:21:46 -06:00
1 parent d9a86e1873
commit 847c4dc765
16 files changed
+304 -120

No files matched your search

+3
View File
@@ -16,6 +16,7 @@ namespace CalamityMod.Effects
public static Effect FabstaffRayShader;
public static Effect ScarletDevilShader;
public static Effect BordernadoFireShader;
public static Effect PrismCrystalShader;
public static void LoadShaders()
{
@@ -29,6 +30,7 @@ namespace CalamityMod.Effects
FabstaffRayShader = CalamityMod.Instance.GetEffect("Effects/FabstaffStreak");
ScarletDevilShader = CalamityMod.Instance.GetEffect("Effects/ScarletDevilStreak");
BordernadoFireShader = CalamityMod.Instance.GetEffect("Effects/BordernadoFire");
PrismCrystalShader = CalamityMod.Instance.GetEffect("Effects/PrismCrystalStreak");
Filters.Scene["CalamityMod:Astral"] = new Filter(new AstralScreenShaderData(new Ref<Effect>(AstralFogShader), "AstralPass").UseColor(0.18f, 0.08f, 0.24f), EffectPriority.VeryHigh);
@@ -41,6 +43,7 @@ namespace CalamityMod.Effects
GameShaders.Misc["CalamityMod:FabstaffRay"] = new MiscShaderData(new Ref<Effect>(FabstaffRayShader), "TrailPass");
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:PrismCrystal"] = new MiscShaderData(new Ref<Effect>(PrismCrystalShader), "TrailPass");
}
}
}
+70
View File
@@ -0,0 +1,70 @@
sampler uImage0 : register(s0);
sampler uImage1 : register(s1);
float3 uColor;
float3 uSecondaryColor;
float uOpacity;
float uSaturation;
float uRotation;
float uTime;
float4 uSourceRect;
float2 uWorldPosition;
float uDirection;
float3 uLightSource;
float2 uImageSize0;
float2 uImageSize1;
matrix uWorldViewProjection;
struct VertexShaderInput
{
float4 Position : POSITION0;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
};
VertexShaderOutput VertexShaderFunction(in VertexShaderInput input)
{
VertexShaderOutput output = (VertexShaderOutput)0;
float4 pos = mul(input.Position, uWorldViewProjection);
output.Position = pos;
output.Color = input.Color;
output.TextureCoordinates = input.TextureCoordinates;
return output;
}
// The X coordinate is the trail completion, the Y coordinate is the same as any other.
// This is simply how the primitive TextCoord is layed out in the C# code.
// Inputted images go into uImage1 sampler, in case you have a noise map or something similar.
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
float4 color = input.Color;
float2 coords = input.TextureCoordinates;
float areaFadeGlow = lerp(1.2, 17, coords.x);
if (coords.x < 0.25)
areaFadeGlow = lerp(areaFadeGlow, 1.2, 1 - coords.x / 0.25);
float2 mapColor = tex2D(uImage1, float2(frac(coords.x - uTime * 4.2), coords.y));
float opacity = pow(sin(coords.y * 3.141), areaFadeGlow) + 0.6 * lerp(1.1, 0.3, coords.x) * mapColor.r;
if (coords.x > 0.66)
opacity = lerp(opacity, 0, (coords.x - 0.66) / 0.3);
return color * opacity;
}
technique Technique1
{
pass TrailPass
{
VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
Binary file not shown.
@@ -6,18 +6,22 @@ using Terraria.ModLoader;
namespace CalamityMod.Items.Weapons.Melee
{
public class PrismSaw : ModItem
public class PhotonRipper : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Prism Saw");
DisplayName.SetDefault("Photon Ripper");
Tooltip.SetDefault("Unleashes a flurry of prismatic crystals at extremely fast speeds\n" +
"");
}
public override void SetDefaults()
{
item.height = 134;
item.width = 54;
item.damage = 3781;
item.damage = 2581;
item.axe = 3330;
item.axe /= 5;
item.melee = true;
item.noMelee = true;
item.noUseGraphic = true;
@@ -29,7 +33,7 @@ namespace CalamityMod.Items.Weapons.Melee
item.autoReuse = false;
item.value = CalamityGlobalItem.RarityVioletBuyPrice;
item.rare = ItemRarityID.Red;
item.shoot = ModContent.ProjectileType<PrismSawProjectile>();
item.shoot = ModContent.ProjectileType<PhotonRipperProjectile>();
item.shootSpeed = 1f;
item.Calamity().customRarity = CalamityRarity.Violet;
}
File renamed without changes.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

+1 -1
View File
@@ -71,7 +71,7 @@ namespace CalamityMod.Projectiles.Boss
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
if (TornadoDrawer is null)
TornadoDrawer = new PrimitiveTrail(_ => projectile.width * 0.5f + 16f, ColorFunction, true, GameShaders.Misc["CalamityMod:Bordernado"]);
TornadoDrawer = new PrimitiveTrail(_ => projectile.width * 0.5f + 16f, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:Bordernado"]);
GameShaders.Misc["CalamityMod:Bordernado"].SetShaderTexture(ModContent.GetTexture("Terraria/Misc/Perlin"));
Vector2[] drawPoints = new Vector2[5];
@@ -308,7 +308,7 @@ namespace CalamityMod.Projectiles.DraedonsArsenal
Rectangle frame = IsSmall ? bladeTexture.Frame(1, 3, 0, BladeFrameY) : bladeTexture.Frame(3, 7, BladeFrameX, BladeFrameY);
if (TrailDrawer is null)
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, true, GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"]);
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"]);
GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/SwordSlashTexture"));
+4 -2
View File
@@ -1,6 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.Graphics.Shaders;
@@ -49,6 +50,7 @@ namespace CalamityMod.Projectiles.Magic
}
else
projectile.velocity *= 1.004f;
projectile.rotation = projectile.velocity.ToRotation();
}
internal Color ColorFunction(float completionRatio)
@@ -68,10 +70,10 @@ namespace CalamityMod.Projectiles.Magic
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
if (TrailDrawer is null)
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, false, GameShaders.Misc["CalamityMod:FabstaffRay"]);
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.SmoothCatmullRomPointRetreivalFunction, GameShaders.Misc["CalamityMod:FabstaffRay"]);
GameShaders.Misc["CalamityMod:FabstaffRay"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/FabstaffStreak"));
TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 8);
TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 0, projectile.oldRot);
return false;
}
+3 -3
View File
@@ -78,10 +78,10 @@ namespace CalamityMod.Projectiles.Magic
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
if (TrailDrawer is null)
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, true, GameShaders.Misc["CalamityMod:FabstaffRay"]);
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:FabstaffRay"]);
GameShaders.Misc["CalamityMod:FabstaffRay"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/FabstaffStreak"));
TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 50);
GameShaders.Misc["CalamityMod:FabstaffRay"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak"));
TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 76);
return false;
}
File renamed without changes.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

@@ -1,5 +1,4 @@
using CalamityMod.Dusts;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
@@ -8,13 +7,15 @@ using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Melee
{
public class PrismSawProjectile : ModProjectile
public class PhotonRipperProjectile : ModProjectile
{
public Player Owner => Main.player[projectile.owner];
public const int CrystalShootRate = 5;
public const int ChargeUpTime = 5;
public ref float Time => ref projectile.ai[0];
public ref float OriginalDamage => ref projectile.ai[1];
public float ChargeUpPower => MathHelper.Clamp((float)Math.Pow(Time / 240f, 1.6D), 0f, 1f);
public override void SetStaticDefaults() => DisplayName.SetDefault("Verrrrrrrry over the top chainsaw thing");
public float ChargeUpPower => MathHelper.Clamp((float)Math.Pow(Time / ChargeUpTime, 1.6D), 0f, 1f);
public override void SetStaticDefaults() => DisplayName.SetDefault("An extraordinarily cost inefficient chainsaw"); // Seriously though Draedon this seems a bit over the top lmfao.
public override void SetDefaults()
{
@@ -26,17 +27,18 @@ namespace CalamityMod.Projectiles.Melee
projectile.melee = true;
projectile.ownerHitCheck = true;
projectile.usesIDStaticNPCImmunity = true;
projectile.idStaticNPCHitCooldown = 2;
projectile.idStaticNPCHitCooldown = 8;
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Texture2D texture = Main.projectileTexture[projectile.type];
Texture2D glowmaskTexture = ModContent.GetTexture("CalamityMod/Projectiles/Melee/PrismSawGlowmask");
Texture2D glowmaskTexture = ModContent.GetTexture("CalamityMod/Projectiles/Melee/PhotonRipperGlowmask");
Rectangle glowmaskRectangle = glowmaskTexture.Frame(1, 6, 0, projectile.frame);
Vector2 origin = texture.Size() * 0.5f;
Vector2 drawPosition = projectile.Center - Main.screenPosition;
SpriteEffects direction = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
spriteBatch.Draw(texture, drawPosition, null, projectile.GetAlpha(lightColor), projectile.rotation, origin, projectile.scale, direction, 0f);
spriteBatch.Draw(glowmaskTexture, drawPosition, glowmaskRectangle, Color.White, projectile.rotation, origin, projectile.scale, direction, 0f);
return false;
@@ -47,20 +49,23 @@ namespace CalamityMod.Projectiles.Melee
PlayChainsawSounds();
DetermineDamage();
Vector2 playerRotatedPoint = Owner.RotatedRelativePoint(Owner.MountedCenter);
// Determines the owner's position whilst incorporating their fullRotation field.
// It uses vector transformation on a Z rotation matrix based on said rotation under the hood.
// This is essentially just the pure mathematical definition of the RotatedBy method.
Vector2 playerRotatedPosition = Owner.RotatedRelativePoint(Owner.MountedCenter);
if (Main.myPlayer == projectile.owner)
{
if (Owner.channel && !Owner.noItems && !Owner.CCed)
HandleChannelMovement(playerRotatedPoint);
HandleChannelMovement(playerRotatedPosition);
else
projectile.Kill();
}
DetermineVisuals(playerRotatedPoint);
DetermineVisuals(playerRotatedPosition);
ManipulatePlayerValues();
EmitPrettyDust();
if (Time > 90f && Time % 36f == 35f)
if (Time % CrystalShootRate == CrystalShootRate - 1f)
ReleasePrismTeeth();
// Prevent the projectile from dying normally. However, if anything for whatever reason
@@ -74,7 +79,7 @@ namespace CalamityMod.Projectiles.Melee
{
if (projectile.soundDelay <= 0)
{
Main.PlaySound(SoundID.Item22, projectile.position);
Main.PlaySound(SoundID.Item22, projectile.Center);
projectile.soundDelay = (int)MathHelper.Lerp(30f, 12f, ChargeUpPower);
}
}
@@ -88,32 +93,38 @@ namespace CalamityMod.Projectiles.Melee
projectile.netUpdate = true;
}
// And then do time based calculations. This does not execute if the original damage is 0.
// And then do time based damage calculations. This does not execute if the original damage is 0.
if (OriginalDamage != 0f)
projectile.damage = (int)MathHelper.SmoothStep(OriginalDamage * 0.36f, OriginalDamage, ChargeUpPower);
}
public void DetermineVisuals(Vector2 playerRotatedPoint)
public void DetermineVisuals(Vector2 playerRotatedPosition)
{
float velocityAngle = projectile.velocity.ToRotation();
projectile.rotation = velocityAngle;
float directionAngle = projectile.velocity.ToRotation();
projectile.rotation = directionAngle;
int oldDirection = projectile.spriteDirection;
if (oldDirection == -1)
projectile.rotation += MathHelper.Pi;
projectile.direction = projectile.spriteDirection = (Math.Cos(velocityAngle) > 0).ToDirectionInt();
projectile.direction = projectile.spriteDirection = (Math.Cos(directionAngle) > 0).ToDirectionInt();
// If the direction differs from what it originaly was, undo the previous 180 degree turn.
// If this is not done, the chainsaw will have 1 frame of rotational "jitter" when the direction changes based on the
// original angle. This effect looks very strange in-game.
if (projectile.spriteDirection != oldDirection)
projectile.rotation -= MathHelper.Pi;
// Positioning close to the end of the player's arm.
projectile.position = playerRotatedPoint - projectile.Size * 0.5f + velocityAngle.ToRotationVector2() * 30f;
// Positioning close to the player's arm.
projectile.position = playerRotatedPosition - projectile.Size * 0.5f + directionAngle.ToRotationVector2() * 30f;
// Update the position a tiny bit every frame at random to make it look like the saw is vibrating.
// It is reset on the next frame.
projectile.position += Main.rand.NextVector2Circular(1.4f, 1.4f);
// Update glowmask frames.
// Smoothstep is essentially like a linear interpolation but instead of being a straight line its
// curve is pseudo-logistic, with low increases at the ends of the curve.
projectile.frameCounter += (int)MathHelper.SmoothStep(12f, 33f, ChargeUpPower);
if (projectile.frameCounter >= 32)
{
@@ -122,28 +133,23 @@ namespace CalamityMod.Projectiles.Melee
}
}
public void HandleChannelMovement(Vector2 playerRotatedPoint)
public void HandleChannelMovement(Vector2 playerRotatedPosition)
{
float speed = 1f;
if (Owner.ActiveItem().shoot == projectile.type)
speed = Owner.ActiveItem().shootSpeed * projectile.scale;
Vector2 idealAimDirection = (Main.MouseWorld - playerRotatedPosition).SafeNormalize(Vector2.UnitX * Owner.direction);
Vector2 currentAimDirection = projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction);
Vector2 idealAimDirection = (Main.MouseWorld - playerRotatedPoint).SafeNormalize(Vector2.UnitX * Owner.direction);
float angularAimVelocity = 0.16f;
float angularAimVelocity = 0.15f;
float directionAngularDisparity = projectile.velocity.AngleBetween(idealAimDirection) / MathHelper.Pi;
// Increase the turn speed if close to the ideal direction, since successive linear interpolations
// are asymptotic.
angularAimVelocity += MathHelper.Lerp(0f, 0.25f, Utils.InverseLerp(0.28f, 0.08f, directionAngularDisparity, true));
if (directionAngularDisparity < 0.02f)
projectile.velocity = Vector2.Lerp(currentAimDirection, idealAimDirection, angularAimVelocity);
if (directionAngularDisparity > 0.02f)
projectile.velocity = Vector2.Lerp(projectile.velocity, idealAimDirection, angularAimVelocity);
else
projectile.velocity = idealAimDirection;
projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction) * speed;
projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction);
}
public void ManipulatePlayerValues()
@@ -163,6 +169,9 @@ namespace CalamityMod.Projectiles.Melee
for (int i = 0; i < 2; i++)
{
Vector2 spawnPosition = projectile.Center + projectile.velocity * 35f;
// Spawn the dust a little bit on the chainsaw. X variance is less than Y variance to ensure that dust does not
// spawn too far from the blade.
spawnPosition += Main.rand.NextVector2CircularEdge(9f, 35f).RotatedBy(projectile.velocity.ToRotation() + MathHelper.PiOver2);
Dust rainbowSpark = Dust.NewDustPerfect(spawnPosition, 261);
@@ -175,11 +184,27 @@ namespace CalamityMod.Projectiles.Melee
public void ReleasePrismTeeth()
{
// Play the sound that the crystal vile shard uses.
// Hopefully this isn't too cancerous to listen to, given the shoot rate of the crystals.
Main.PlaySound(SoundID.Item101, projectile.Center);
if (Main.myPlayer != projectile.owner)
return;
float shootReach = MathHelper.SmoothStep(projectile.width * 1.2f, projectile.width * 2.25f + 20f, ChargeUpPower);
Projectile.NewProjectile(Owner.Center, projectile.velocity, ModContent.ProjectileType<PrismTooth>(), projectile.damage / 2, 0f, projectile.owner, 0f, shootReach);
float shootReach = MathHelper.SmoothStep(projectile.width * 1.8f, projectile.width * 5.3f + 16f, ChargeUpPower);
// Incorporate item shoot speed into the range of the crystals.
shootReach *= Owner.ActiveItem().shootSpeed;
float distanceFromMouse = Owner.Distance(Main.MouseWorld);
// If the distance to the mouse is less than the base reach, reach only to mouse.
// This way the player can more directly control the crystals if they want.
// This comes with a small constant offset to cancel out other factors.
if (distanceFromMouse < shootReach && distanceFromMouse > 40f)
shootReach = distanceFromMouse + 32f;
Projectile.NewProjectile(Owner.Center, projectile.velocity, ModContent.ProjectileType<PrismTooth>(), projectile.damage / 2, 0f, projectile.owner, shootReach, projectile.whoAmI);
}
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
File renamed without changes.

Before

Width:  |  Height:  |  Size: 715 B

After

Width:  |  Height:  |  Size: 715 B

+86 -47
View File
@@ -1,8 +1,8 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using Terraria;
using Terraria.GameContent.Achievements;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;
@@ -12,86 +12,125 @@ namespace CalamityMod.Projectiles.Melee
public class PrismTooth : ModProjectile
{
internal PrimitiveTrail TrailDrawer;
public const int Lifetime = 30;
public const int Lifetime = 80;
public Player Owner => Main.player[projectile.owner];
public ref float Time => ref projectile.ai[0];
public ref float ShootReach => ref projectile.ai[1];
public ref float ShootReach => ref projectile.ai[0];
public ref float Time => ref projectile.ai[1];
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Prism Tooth");
{
DisplayName.SetDefault("Prism Tooth");
ProjectileID.Sets.TrailingMode[projectile.type] = 2;
ProjectileID.Sets.TrailCacheLength[projectile.type] = 36;
}
public override void SetDefaults()
{
projectile.width = projectile.height = 35;
public override void SetDefaults()
{
projectile.scale = 0.6f;
projectile.width = projectile.height = 40;
projectile.friendly = true;
projectile.penetrate = 1;
projectile.timeLeft = Lifetime;
projectile.melee = true;
}
public override void SendExtraAI(BinaryWriter writer) => writer.Write((byte)projectile.direction);
public override void ReceiveExtraAI(BinaryReader reader) => projectile.direction = reader.ReadByte();
projectile.tileCollide = false;
projectile.penetrate = -1;
projectile.extraUpdates = 5;
projectile.usesLocalNPCImmunity = true;
projectile.localNPCHitCooldown = 4 * projectile.MaxUpdates;
projectile.timeLeft = Lifetime;
projectile.melee = true;
}
public override void AI()
{
// Determine the initial direction of the tooth in terms of its orbit.
if (Main.myPlayer == projectile.owner && projectile.spriteDirection == 0)
{
projectile.spriteDirection = Main.rand.NextBool(2).ToDirectionInt();
projectile.netUpdate = true;
}
projectile.rotation = projectile.velocity.ToRotation() + MathHelper.Pi * Time / Lifetime;
projectile.rotation = MathHelper.Pi * Time / Lifetime;
if (projectile.spriteDirection == -1)
projectile.rotation = MathHelper.Pi - projectile.rotation;
projectile.rotation += projectile.velocity.ToRotation();
Vector2 baseDirection = (MathHelper.TwoPi * Time / Lifetime - MathHelper.PiOver2).ToRotationVector2();
baseDirection.X *= 0.25f;
// Constrain the Y offset into the bounds of 0-1 instead of -1-1. This prevents
// the crystal from flying behind the owner. In this context, the Y offset becomes how far away the
// crystal is from its own in terms of reach.
baseDirection.Y = baseDirection.Y * 0.5f + 0.5f;
Vector2 positionOffset = baseDirection * ShootReach;
// Don't allow the X offset to go too far.
// This hard limit turns the squashed circle into bending, semi-rectangular shape.
if (Math.Abs(positionOffset.X) > 45f)
positionOffset.X = Math.Sign(baseDirection.X) * 45f;
// In this context, the velocity is simply the initial direction as a unit vector- it does not
// actually influence movement in any way.
float angle = MathHelper.TwoPi * Time / Lifetime - MathHelper.PiOver2;
if (projectile.spriteDirection == -1)
angle += MathHelper.Pi;
positionOffset = positionOffset.RotatedBy(projectile.velocity.ToRotation() - MathHelper.PiOver2);
Vector2 baseDirection = angle.ToRotationVector2();
baseDirection.X *= 0.25f;
baseDirection.Y = baseDirection.Y * 0.5f + 0.5f;
baseDirection = baseDirection.RotatedBy(projectile.velocity.ToRotation() - MathHelper.PiOver2);
projectile.Center = Owner.RotatedRelativePoint(Owner.MountedCenter) + baseDirection * ShootReach;
projectile.Center = Owner.RotatedRelativePoint(Owner.MountedCenter) + projectile.velocity * 42f + positionOffset;
projectile.Opacity = Utils.InverseLerp(0f, 12f, Time, true) * Utils.InverseLerp(Lifetime, Lifetime - 12f, Time, true);
// Destroy trees within the range of the past 20 oldPos positions.
for (int i = 0; i < 20; i++)
{
Point pointToCheck = (projectile.oldPos[i] + projectile.Size * 0.5f).ToTileCoordinates();
AbsolutelyFuckingAnnihilateTrees(pointToCheck.X, pointToCheck.Y);
}
Time++;
}
public override Color? GetAlpha(Color lightColor)
public void AbsolutelyFuckingAnnihilateTrees(int x, int y)
{
float hue = (projectile.identity % 9f / 9f + projectile.timeLeft / (float)Lifetime) % 1f;
return Color.Lerp(lightColor, Main.hslToRgb(hue, 0.95f, 0.55f), 0.35f) * projectile.Opacity;
Tile tileAtPosition = CalamityUtils.ParanoidTileRetrieval(x, y);
// Ignore tiles that are not active and are not breakable by axes.
if (!tileAtPosition.active() || !Main.tileAxe[tileAtPosition.type])
return;
// Don't attempt to mine the tile if for whatever reason it's not supposed to be broken.
if (!WorldGen.CanKillTile(x, y))
return;
AchievementsHelper.CurrentlyMining = true;
WorldGen.KillTile(x, y);
if (Main.netMode == NetmodeID.MultiplayerClient)
NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, x, y);
AchievementsHelper.CurrentlyMining = false;
}
internal float WidthFunction(float completionRatio) => 54f;
public override Color? GetAlpha(Color lightColor) => Color.White;
internal float WidthFunction(float completionRatio) => projectile.scale * 24f * (1f - Utils.InverseLerp(0.7f, 1f, completionRatio, true));
internal Color ColorFunction(float completionRatio)
{
Color color = Color.Lerp(Color.White, Color.Violet, Utils.InverseLerp(0f, 0.7f, completionRatio, true)) * (1f - Utils.InverseLerp(0f, 0.98f, completionRatio, true));
color.A /= 2;
return color;
float hue = (projectile.identity % 9f / 9f + completionRatio * 0.7f) % 1f;
return Color.Lerp(Color.White, Main.hslToRgb(hue, 0.95f, 0.55f), 0.35f) * projectile.Opacity;
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
if (TrailDrawer is null)
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, false, GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"]);
if (Time <= 5f)
return true;
GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak"));
TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition + projectile.velocity.SafeNormalize(Vector2.Zero) * 86f, 60);
if (TrailDrawer is null)
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:PrismCrystal"]);
// Variable adjustment vector used to prevent the trail for starting somewhat that isn't behind
// the crystal. This may appear in small amounts, with offsets of a few pixels, but at the speed
// these crystals go, it's probably not something to worry too much about.
Vector2 generalOffset = projectile.rotation.ToRotationVector2().RotatedBy(MathHelper.PiOver2) * 15f;
generalOffset += projectile.rotation.ToRotationVector2() * -5f * (float)Math.Sin(projectile.rotation);
// Mess with the oldPos array so that the trail always points towards the crystal.
Vector2 oldPosition = projectile.oldPos[1];
projectile.oldPos[1] = projectile.oldPos[0] - projectile.rotation.ToRotationVector2() * Vector2.Distance(projectile.oldPos[0], projectile.oldPos[1]);
// Revert back if the above calculations caused any NaNs.
if (projectile.oldPos[1].HasNaNs())
projectile.oldPos[1] = oldPosition;
GameShaders.Misc["CalamityMod:PrismCrystal"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak"));
TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f + generalOffset - Main.screenPosition, 65);
return true;
}
// Prevent the crystals from utilizing velocity. Their movement is entirely dependant on Center setting.
public override bool ShouldUpdatePosition() => false;
}
}
+1 -1
View File
@@ -176,7 +176,7 @@ namespace CalamityMod.Projectiles.Rogue
else
{
if (TrailDrawer is null)
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, false, GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"]);
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"]);
GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak"));
TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition + projectile.velocity.SafeNormalize(Vector2.Zero) * 86f, 60);
+1 -1
View File
@@ -140,7 +140,7 @@ namespace CalamityMod.Projectiles.Summon
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
if (LightningDrawer is null)
LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, false);
LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction);
LightningDrawer.Draw(projectile.oldPos.Where(oldPos => oldPos != Vector2.Zero), projectile.Size * 0.5f - Main.screenPosition, 300);
return false;
+69 -28
View File
@@ -38,21 +38,24 @@ 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 BasicEffect BaseEffect;
public MiscShaderData SpecialShader;
public TrailPointRetrievalFunction TrailPointFunction;
public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, bool useSmoothening = true, MiscShaderData specialShader = null)
public delegate List<Vector2> TrailPointRetrievalFunction(IEnumerable<Vector2> originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable<float> originalRotations = null);
public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, TrailPointRetrievalFunction pointFunction = null, MiscShaderData 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;
// Default to bezier smoothening if nothing else is inputted.
if (pointFunction is null)
pointFunction = SmoothBezierPointRetreivalFunction;
TrailPointFunction = pointFunction;
if (specialShader != null)
SpecialShader = specialShader;
@@ -90,29 +93,31 @@ namespace CalamityMod
BaseEffect.Projection = effectProjection;
}
public List<Vector2> GetTrailPoints(IEnumerable<Vector2> originalPositions, Vector2 generalOffset, int totalTrailPoints)
public static List<Vector2> RigidPointRetreivalFunction(IEnumerable<Vector2> originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable<float> originalRotations = null)
{
// 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>();
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);
}
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;
}
// 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 static List<Vector2> SmoothBezierPointRetreivalFunction(IEnumerable<Vector2> originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable<float> originalRotations = null)
{
List<Vector2> controlPoints = new List<Vector2>();
for (int i = 0; i < originalPositions.Count(); i++)
{
@@ -126,6 +131,32 @@ namespace CalamityMod
return controlPoints.Count <= 1 ? controlPoints : bezierCurve.GetPoints(totalTrailPoints);
}
public static List<Vector2> SmoothCatmullRomPointRetreivalFunction(IEnumerable<Vector2> originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable<float> originalRotations)
{
List<Vector2> smoothenedPoints = new List<Vector2>();
for (int i = 0; i < originalPositions.Count() - 1; i++)
{
if (originalPositions.ElementAt(i) == Vector2.Zero || originalPositions.ElementAt(i + 1) == Vector2.Zero)
continue;
float currentRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i));
float aheadRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i + 1));
int pointsToAdd = (int)(Math.Abs(aheadRotation - currentRotation) * 50f / MathHelper.Pi) + 4;
if (pointsToAdd > 6)
{
int v = 7;
}
float segmentLength = Vector2.Distance(originalPositions.ElementAt(i), originalPositions.ElementAt(i + 1));
float increment = 1f / (pointsToAdd + 2);
Vector2 end = originalPositions.ElementAt(i) + currentRotation.ToRotationVector2() * segmentLength;
Vector2 front = originalPositions.ElementAt(i + 1) + aheadRotation.ToRotationVector2() * -segmentLength;
for (float j = increment; j < 1f; j += increment)
smoothenedPoints.Add(Vector2.CatmullRom(end, originalPositions.ElementAt(i), originalPositions.ElementAt(i + 1), front, j) + generalOffset);
}
return smoothenedPoints;
}
public VertexPosition2DColor[] GetVerticesFromTrailPoints(List<Vector2> trailPoints)
{
List<VertexPosition2DColor> vertices = new List<VertexPosition2DColor>();
@@ -181,19 +212,29 @@ namespace CalamityMod
return indices;
}
public void Draw(IEnumerable<Vector2> originalPositions, Vector2 generalOffset, int totalTrailPoints)
public void Draw(IEnumerable<Vector2> originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable<float> originalRotations = null)
{
Main.instance.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
List<Vector2> trailPoints = GetTrailPoints(originalPositions, generalOffset, totalTrailPoints);
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 (originalPositions.Count() <= 1 || trailPoints.Count <= 1)
if (originalPositions.Count() <= 2 || trailPoints.Count <= 2)
return;
// If the trail point has any NaN positions, don't draw anything.
if (trailPoints.Any(point => point.HasNaNs()))
return;
UpdateBaseEffect(out Matrix projection, out Matrix view);
VertexPosition2DColor[] vertices = GetVerticesFromTrailPoints(trailPoints);
short[] triangleIndices = GetIndicesFromTrailPoints(trailPoints.Count);
// Don't draw anything if the indicies/vertices are in any way invalid.
// If they are, the graphics engine, along with the entire game, will crash.
if (triangleIndices.Length % 6 != 0 || vertices.Length % 2 != 0)
return;
if (SpecialShader != null)
{
SpecialShader.Shader.Parameters["uWorldViewProjection"].SetValue(view * projection);