diff --git a/Effects/Compiler/SwingEffect.fx b/Effects/Compiler/SwingEffect.fx deleted file mode 100644 index 994c747342..0000000000 --- a/Effects/Compiler/SwingEffect.fx +++ /dev/null @@ -1,73 +0,0 @@ -float rotation; // The rotation of the sword sprite. -//float2 spriteDimensions; //The size of the sprite (necessary as the shader only gives us a map between 0 and 1). -float pommelToOriginPercent; //I have no idea for a better variable name. This is the perccentage of the full lenght between the rotation origin and the sword's tip that is an empty gap between it and the bottom left of the sword. - -texture sampleTexture; -sampler2D Texture1Sampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = wrap; AddressV = wrap; }; - -float realCos(float value) -{ - return sin(value + 1.57079); -} - -//This only works on square sprites. Commented out code can be found for attempts to make it work on non square sprites but my god is it a headache to work with transform matrices -//In a context like that. Gee. -//At this point i barely understand why some of it works but yea it just happens. -float4 main(float2 uv : TEXCOORD) : COLOR -{ - if (uv.x < 0.005 || uv.x > 1 - 0.005 || uv.y < 0.005 || uv.y > 1 - 0.005) - return float4(1, 0, 0, 1); - if (length(uv - float2(0.5, 0.5)) < 0.01) - return float4(1, 0, 0, 1); - - //Transformation matrices - //float2x2 squareify = float2x2(1, 0, 0, 1); - //float2x2 unsquareify = float2x2(1, 0, 0, 1); - - - float2x2 rotate = float2x2(realCos(rotation), -sin(rotation), sin(rotation), realCos(rotation)); - float spriteDiagonal = 1 / (sqrt(2) / 4); - float spriteDiagonalReal = spriteDiagonal * (1 / (1 - pommelToOriginPercent)); - - float2x2 downscale = float2x2(spriteDiagonalReal, 0, 0, spriteDiagonalReal); - float displaceFromOrigin = (1 / (1 - pommelToOriginPercent)) * (1 - 0.5 * (1 - pommelToOriginPercent)); //It's complicated as fuck to explain, but this gets the distance of the displacement. - - /* - //Since the rotation effect stretches and squishes sprites that arent square, we have to turn it into a square before the rotation (and then unsquareify it after its done) - if (spriteDimensions.x != spriteDimensions.y) - { - float aspectRatio = max(spriteDimensions.x, spriteDimensions.y) / min(spriteDimensions.x, spriteDimensions.y); - //Rescale matrix - squareify = float2x2(1, 0, 0, aspectRatio); - unsquareify = float2x2(1 / aspectRatio, 0, 0, 1 / aspectRatio); - - if (spriteDimensions.x > spriteDimensions.y) - { - squareify = float2x2(aspectRatio, 0, 0, 1); - unsquareify = float2x2(1 / aspectRatio, 0, 0, 1 / aspectRatio); - } - } - */ - - uv += float2(-0.5, -0.5); //remap the uv to (-0.5, -0.5) - (0.5, 0.5) for trig to work. - //uv = mul(uv, squareify); - uv = mul(uv, rotate); - uv = mul(uv, downscale); - //uv = mul(uv, unsquareify); - uv += displaceFromOrigin; - uv += float2(0.5, 0.5); //remap the uv properly - - //Crop (Attempting to sample a texture with coordinates that arent between 0 to 1 wraps it around - if (uv.x < 0 || uv.x >= 1 || uv.y < 0 || uv.y >= 1) - return float4(0, 0, 0, 0); - - return tex2D(Texture1Sampler, uv); -} - -technique Technique1 -{ - pass SwingPass - { - PixelShader = compile ps_2_0 main(); - } -} diff --git a/Effects/Compiler/SwingEffect.xnb b/Effects/Compiler/SwingEffect.xnb deleted file mode 100644 index 196fd3a582..0000000000 Binary files a/Effects/Compiler/SwingEffect.xnb and /dev/null differ diff --git a/Effects/RotateSprite.fx b/Effects/RotateSprite.fx index e26f4507e0..bd91a83ed0 100644 --- a/Effects/RotateSprite.fx +++ b/Effects/RotateSprite.fx @@ -1,5 +1,6 @@ float rotation; // The rotation of the sprite. -float2 spriteDimensions; +float4 color; + texture sampleTexture; sampler2D Texture1Sampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = wrap; AddressV = wrap; }; @@ -25,7 +26,7 @@ float4 main(float2 uv : TEXCOORD) : COLOR if (uv.x < 0 || uv.x >= 1 || uv.y < 0 || uv.y >= 1) return float4(0, 0, 0, 0); - return tex2D(Texture1Sampler, uv); + return tex2D(Texture1Sampler, uv) * color; } technique Technique1 diff --git a/Effects/RotateSprite.xnb b/Effects/RotateSprite.xnb index 22bb297ec3..a4475a6c47 100644 Binary files a/Effects/RotateSprite.xnb and b/Effects/RotateSprite.xnb differ diff --git a/Effects/SwingSprite.fx b/Effects/SwingSprite.fx index 6346813917..62e1157275 100644 --- a/Effects/SwingSprite.fx +++ b/Effects/SwingSprite.fx @@ -1,6 +1,7 @@ float rotation; // The rotation of the sword sprite. //float2 spriteDimensions; //The size of the sprite (necessary as the shader only gives us a map between 0 and 1). float pommelToOriginPercent; //I have no idea for a better variable name. This is the perccentage of the full lenght between the rotation origin and the sword's tip that is an empty gap between it and the bottom left of the sword. +float4 color; texture sampleTexture; sampler2D Texture1Sampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = wrap; AddressV = wrap; }; @@ -55,7 +56,7 @@ float4 main(float2 uv : TEXCOORD) : COLOR if (uv.x < 0 || uv.x >= 1 || uv.y < 0 || uv.y >= 1) return float4(0, 0, 0, 0); - return tex2D(Texture1Sampler, uv); + return tex2D(Texture1Sampler, uv) * color; } technique Technique1 diff --git a/Effects/SwingSprite.xnb b/Effects/SwingSprite.xnb index 8c0d08b228..f3b222ac54 100644 Binary files a/Effects/SwingSprite.xnb and b/Effects/SwingSprite.xnb differ diff --git a/ExtraTextures/BlobbyNoise.png b/ExtraTextures/BlobbyNoise.png new file mode 100644 index 0000000000..4d7b4b179f Binary files /dev/null and b/ExtraTextures/BlobbyNoise.png differ diff --git a/Items/Weapons/Melee/Exoblade.cs b/Items/Weapons/Melee/Exoblade.cs index 8923fd7426..156db390f7 100644 --- a/Items/Weapons/Melee/Exoblade.cs +++ b/Items/Weapons/Melee/Exoblade.cs @@ -17,6 +17,8 @@ namespace CalamityMod.Items.Weapons.Melee { public static readonly SoundStyle SwingSound = new("CalamityMod/Sounds/Item/ExobladeSwing") { MaxInstances = 3, PitchVariance = 0.6f, Volume = 0.8f }; public static readonly SoundStyle BigSwingSound = new("CalamityMod/Sounds/Item/ExobladeBigSwing") { MaxInstances = 3, PitchVariance = 0.2f }; + public static readonly SoundStyle BeamHitSound = new("CalamityMod/Sounds/Item/ExobladeBeamSlash") { Volume = 0.4f, PitchVariance = 0.2f }; + public static int BeamNoHomeTime = 24; @@ -27,7 +29,7 @@ namespace CalamityMod.Items.Weapons.Melee public static float LungeDamageFactor = 1.75f; - public static int LungeCooldown = 60; + public static int LungeCooldown = 60 * 3; //Projectile has 3 updates : aka 1 second public static float LungeMaxCorrection = MathHelper.PiOver4 * 0.05f; @@ -37,7 +39,7 @@ namespace CalamityMod.Items.Weapons.Melee public static float PercentageOfAnimationSpentLunging = 0.6f; - public static int OpportunityForBigSlash = 37; + public static int OpportunityForBigSlash = 37 * 3; public static float BigSlashUpscaleFactor = 1.5f; diff --git a/Particles/SlashSmear.png b/Particles/SlashSmear.png new file mode 100644 index 0000000000..2daf015434 Binary files /dev/null and b/Particles/SlashSmear.png differ diff --git a/Projectiles/Melee/Exobeam.cs b/Projectiles/Melee/Exobeam.cs index 57e838fc87..2e6030ca21 100644 --- a/Projectiles/Melee/Exobeam.cs +++ b/Projectiles/Melee/Exobeam.cs @@ -7,6 +7,12 @@ using CalamityMod.Items.Weapons.Typeless; using CalamityMod.Items.Weapons.Melee; using Terraria.Graphics.Shaders; using Terraria.Graphics.Effects; +using static CalamityMod.CalamityUtils; +using static Terraria.ModLoader.ModContent; +using System; +using Microsoft.Xna.Framework.Graphics; +using System.Linq; +using ReLogic.Content; namespace CalamityMod.Projectiles.Melee { @@ -14,7 +20,39 @@ namespace CalamityMod.Projectiles.Melee { public int TargetIndex = -1; + public static float MaxWidth = 30; public ref float Time => ref Projectile.ai[0]; + public PrimitiveTrail TrailDrawer = null; + public PrimitiveTrail MiniTrailDrawer = null; + + //public static TrailTexture + + public float TrailLenght + { + get + { + if (Projectile.localAI[0] == -1) + { + float totalLenght = 0; + for (int i = 1; i < ProjectileID.Sets.TrailCacheLength[Projectile.type]; i++) + { + if (Projectile.oldPos[i] == Vector2.Zero) + break; + + totalLenght += (Projectile.oldPos[i] - Projectile.oldPos[i - 1]).Length(); + } + + Projectile.localAI[0] = totalLenght; + } + + return Projectile.localAI[0]; + } + } + + public float TrailCompletionAtWhichTheDomeEnds => TrailLenght < MaxWidth ? TrailLenght : MaxWidth / TrailLenght; + + public static Asset BloomTex; + public static Asset SlashTex; public override void SetStaticDefaults() { @@ -25,8 +63,8 @@ namespace CalamityMod.Projectiles.Melee public override void SetDefaults() { - Projectile.width = 106; - Projectile.height = 106; + Projectile.width = 16; + Projectile.height = 16; Projectile.friendly = true; Projectile.DamageType = DamageClass.Melee; Projectile.ignoreWater = true; @@ -37,17 +75,10 @@ namespace CalamityMod.Projectiles.Melee Projectile.timeLeft = 600; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = Projectile.MaxUpdates * 12; - Projectile.light = 1f; } public override void AI() { - if (Projectile.localAI[1] == 0f) - { - //SoundEngine.PlaySound(SoundID.Item60, Projectile.position); - Projectile.localAI[1] = 1f; - } - // Aim very, very quickly at targets. // This takes a small amount of time to happen, to allow the blade to go in its intended direction before immediately racing // towards the nearest target. @@ -62,18 +93,25 @@ namespace CalamityMod.Projectiles.Melee Vector2 idealVelocity = Projectile.SafeDirectionTo(Main.npc[TargetIndex].Center) * (Projectile.velocity.Length() + 3.5f); Projectile.velocity = Vector2.Lerp(Projectile.velocity, idealVelocity, 0.08f); } + + else + { + Projectile.velocity *= 0.99f; + } } - // Dissipate if colliding with tiles. - if (Time >= Exoblade.BeamNoHomeTime + 16f && Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height)) + Projectile.rotation = Projectile.velocity.ToRotation(); + + if (Main.rand.NextBool()) { - Projectile.Opacity -= 0.08f; - if (Projectile.Opacity <= 0f) - Projectile.Kill(); + Color dustColor = Main.hslToRgb(Main.rand.NextFloat(), 1f, 0.9f); + Dust must = Dust.NewDustPerfect(Projectile.Center + Main.rand.NextVector2Circular(20f, 20f) + Projectile.velocity, 267, Projectile.velocity * -2.6f, 0, dustColor); + must.scale = 0.3f; + must.fadeIn = Main.rand.NextFloat() * 1.2f; + must.noGravity = true; } - Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver4; - Projectile.Opacity = MathHelper.Clamp(Projectile.Opacity + 0.1f, 0f, 1f); + Projectile.scale = Utils.GetLerpValue(0f, 0.1f, Projectile.timeLeft / 600f, true); if (Projectile.FinalExtraUpdate()) Time++; @@ -81,7 +119,7 @@ namespace CalamityMod.Projectiles.Melee public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { - SoundEngine.PlaySound(YanmeisKnife.HitSound with { Volume = YanmeisKnife.HitSound.Volume * 0.35f}, target.Center); + SoundEngine.PlaySound(Exoblade.BeamHitSound, target.Center); if (Main.myPlayer == Projectile.owner) Projectile.NewProjectile(Projectile.GetSource_FromAI(), target.Center, Projectile.velocity * 0.1f, ModContent.ProjectileType(), Projectile.damage, 0f, Projectile.owner, target.whoAmI); @@ -95,12 +133,106 @@ namespace CalamityMod.Projectiles.Melee public override Color? GetAlpha(Color lightColor) => Color.White with { A = 0 } * Projectile.Opacity; + + public float TrailWidth(float completionRatio) + { + float width; + //else + //width = 1 - (completionRatio - TrailCompletionAtWhichTheDomeEnds) / (1f - TrailCompletionAtWhichTheDomeEnds); + + width = Utils.GetLerpValue(1f, 0.4f, completionRatio, true) * (float)Math.Sin(Math.Acos(1 - Utils.GetLerpValue(0f, 0.15f, completionRatio, true))); + + //if (completionRatio <= TrailCompletionAtWhichTheDomeEnds) + // width = (float)Math.Sin(Math.Acos(1 - completionRatio / TrailCompletionAtWhichTheDomeEnds)); + + + width *= Utils.GetLerpValue(0f, 0.1f, Projectile.timeLeft / 600f, true); + + return width * MaxWidth; + } + public Color TrailColor(float completionRatio) + { + Color baseColor = Color.Lerp(Color.Cyan, new Color(0, 0, 255), completionRatio); + + return baseColor; + } + + public float MiniTrailWidth(float completionRatio) => TrailWidth(completionRatio) * 0.8f; + public Color MiniTrailColor(float completionRatio) => Color.White; + + public override bool PreDraw(ref Color lightColor) { if (Projectile.timeLeft > 595) return false; - CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 4); + if (BloomTex == null) + BloomTex = ModContent.Request("CalamityMod/Particles/BloomCircle"); + Texture2D texture = BloomTex.Value; + + Color mainColor = MulticolorLerp((Main.GlobalTimeWrappedHourly * 0.5f + Projectile.whoAmI * 0.12f) % 1, Color.Cyan, Color.Lime, Color.GreenYellow, Color.Goldenrod, Color.Orange); + Color secondaryColor = MulticolorLerp((Main.GlobalTimeWrappedHourly * 0.5f + Projectile.whoAmI * 0.12f + 0.2f) % 1, Color.Cyan, Color.Lime, Color.GreenYellow, Color.Goldenrod, Color.Orange); + + //Draw the bloom unde the trail + Main.EntitySpriteDraw(texture, Projectile.oldPos[2] + Projectile.Size / 2f - Main.screenPosition, null, (mainColor * 0.1f) with { A = 0 }, 0, texture.Size() / 2f, 1.3f * Projectile.scale, 0, 0); + Main.EntitySpriteDraw(texture, Projectile.oldPos[1] + Projectile.Size / 2f - Main.screenPosition, null, (mainColor * 0.5f) with { A = 0 }, 0, texture.Size() / 2f, 0.34f * Projectile.scale, 0, 0); + + + TrailDrawer ??= new(TrailWidth, TrailColor, null, GameShaders.Misc["CalamityMod:ExobladePierce"]); + MiniTrailDrawer ??= new(MiniTrailWidth, MiniTrailColor, null, GameShaders.Misc["CalamityMod:ExobladePierce"]); + + Main.spriteBatch.EnterShaderRegion(); + + GameShaders.Misc["CalamityMod:ExobladePierce"].SetShaderTexture(Request("CalamityMod/ExtraTextures/BasicTrail")); + GameShaders.Misc["CalamityMod:ExobladePierce"].UseImage2("Images/Extra_189"); + GameShaders.Misc["CalamityMod:ExobladePierce"].UseColor(mainColor); + GameShaders.Misc["CalamityMod:ExobladePierce"].UseSecondaryColor(secondaryColor); + GameShaders.Misc["CalamityMod:ExobladePierce"].Apply(); + + GameShaders.Misc["CalamityMod:ExobladePierce"].Apply(); + + TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 30, Projectile.oldRot); + + GameShaders.Misc["CalamityMod:ExobladePierce"].UseColor(Color.White); + GameShaders.Misc["CalamityMod:ExobladePierce"].UseSecondaryColor(Color.White); + + MiniTrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 30, Projectile.oldRot); + + //Code put in cold storage. It looks cool but not the right time for it. + /* + + if (SlashTex == null) + SlashTex = ModContent.Request("CalamityMod/Particles/SlashSmear"); + Texture2D slashTex = SlashTex.Value; + + float swingOpacity = (595 - Projectile.timeLeft) / 595f; + swingOpacity = (float)Math.Pow(Utils.GetLerpValue(0.8f, 0.6f, swingOpacity, true), 0.3); + + if (swingOpacity > 0) + { + float rotation = Main.GlobalTimeWrappedHourly * 7f; + rotation += Projectile.whoAmI * MathHelper.Pi * 1.33f; + + Effect swingFX = Filters.Scene["RotateSprite"].GetShader().Shader; + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, swingFX, Main.GameViewMatrix.TransformationMatrix); + + swingFX.Parameters["rotation"].SetValue(rotation); + Main.EntitySpriteDraw(slashTex, Projectile.oldPos[2] + Projectile.Size / 2f - Main.screenPosition, null, secondaryColor * swingOpacity, Projectile.rotation + MathHelper.PiOver4 * 0.6f, slashTex.Size() / 2f, new Vector2(1f, 2f) * 0.5f * Projectile.scale, 0, 0); + + swingFX.Parameters["rotation"].SetValue(rotation + MathHelper.PiOver4); + Main.EntitySpriteDraw(slashTex, Projectile.oldPos[2] + Projectile.Size / 2f - Main.screenPosition, null, secondaryColor * swingOpacity, Projectile.rotation - MathHelper.PiOver4 * 0.6f, slashTex.Size() / 2f, new Vector2(1f, 2f) * 0.5f * Projectile.scale, 0, 0); + } + */ + + Main.spriteBatch.ExitShaderRegion(); + + //Draw the bloom above the trail + Main.EntitySpriteDraw(texture, Projectile.oldPos[2] + Projectile.Size / 2f - Main.screenPosition, null, (Color.White * 0.2f) with { A = 0 }, 0, texture.Size() / 2f, 0.78f * Projectile.scale, 0, 0); + Main.EntitySpriteDraw(texture, Projectile.oldPos[1] + Projectile.Size / 2f - Main.screenPosition, null, (Color.White * 0.5f) with { A = 0 }, 0, texture.Size() / 2f, 0.2f * Projectile.scale, 0, 0); + + + return false; } } diff --git a/Projectiles/Melee/Exobeam.png b/Projectiles/Melee/Exobeam.png index 78bd48076f..67c64cdd26 100644 Binary files a/Projectiles/Melee/Exobeam.png and b/Projectiles/Melee/Exobeam.png differ diff --git a/Projectiles/Melee/ExobladeProj.cs b/Projectiles/Melee/ExobladeProj.cs index c9d44d5756..651d915c7c 100644 --- a/Projectiles/Melee/ExobladeProj.cs +++ b/Projectiles/Melee/ExobladeProj.cs @@ -304,7 +304,7 @@ namespace CalamityMod.Projectiles.Melee //Freeze the projectile on its last frame, so it can act as a ghost "cooldown" if (Projectile.timeLeft == 1 && State == SwingState.BonkDash && !InPostBonkStasis) { - Projectile.timeLeft = Exoblade.LungeCooldown * Projectile.extraUpdates; + Projectile.timeLeft = Exoblade.LungeCooldown; InPostBonkStasis = true; Owner.fullRotation = 0f; @@ -527,12 +527,30 @@ namespace CalamityMod.Projectiles.Melee Effect swingFX = Filters.Scene["SwingSprite"].GetShader().Shader; swingFX.Parameters["rotation"].SetValue(SwingAngleShift + MathHelper.PiOver4 + (Direction == -1 ? MathHelper.Pi : 0f)); swingFX.Parameters["pommelToOriginPercent"].SetValue(0.05f); + swingFX.Parameters["color"].SetValue(Color.White.ToVector4()); Main.spriteBatch.End(); Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, swingFX, Main.GameViewMatrix.TransformationMatrix); Main.EntitySpriteDraw(texture, Owner.MountedCenter - Main.screenPosition, null, Color.White, BaseRotation, texture.Size() / 2f, SquishVector * 3f * Projectile.scale, direction, 0); + /* + if (PerformingPowerfulSlash) + { + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, swingFX, Main.GameViewMatrix.TransformationMatrix); + + float bouncyProgression = (float)Math.Sin(Progression * MathHelper.Pi); + swingFX.Parameters["color"].SetValue(Color.MediumSpringGreen.ToVector4() with { W = bouncyProgression * 0.5f }); + + for (int i = 0; i < 4; i++) + { + Vector2 offset = (i / 4f * MathHelper.TwoPi + SwingAngleShift + MathHelper.PiOver4).ToRotationVector2() * 2f * Projectile.scale; + Main.EntitySpriteDraw(texture, Owner.MountedCenter - Main.screenPosition + offset, null, Color.White, BaseRotation, texture.Size() / 2f, SquishVector * 3f * Projectile.scale, direction, 0); + } + } + */ + Main.spriteBatch.End(); Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); @@ -581,7 +599,7 @@ namespace CalamityMod.Projectiles.Melee { Owner.itemAnimation = 0; Owner.velocity = Owner.SafeDirectionTo(target.Center) * -Exoblade.ReboundSpeed; - Projectile.timeLeft = (Exoblade.OpportunityForBigSlash + Exoblade.LungeCooldown) * Projectile.extraUpdates; + Projectile.timeLeft = Exoblade.OpportunityForBigSlash + Exoblade.LungeCooldown; InPostBonkStasis = true; Projectile.netUpdate = true; diff --git a/Sounds/Item/ExobladeBeamSlash.ogg b/Sounds/Item/ExobladeBeamSlash.ogg new file mode 100644 index 0000000000..d165cf5c95 Binary files /dev/null and b/Sounds/Item/ExobladeBeamSlash.ogg differ