Start of bonk effect for Exoblade

This commit is contained in:
Dominic committed 2022-07-13 02:23:06 -05:00
1 parent 5949a900ed
commit 10169858fc
8 files changed
+184 -51

No files matched your search

+3
View File
@@ -37,6 +37,7 @@ namespace CalamityMod.Effects
public static Effect BasicPrimitiveShader;
public static Effect ArtemisLaserShader;
public static Effect ExobladeSlashShader;
public static Effect ExobladePierceShader;
public static Effect BaseFusableParticleEdgeShader;
public static Effect AdditiveFusableParticleEdgeShader;
@@ -77,6 +78,7 @@ namespace CalamityMod.Effects
BasicPrimitiveShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/BasicPrimitiveShader", AssetRequestMode.ImmediateLoad).Value;
ArtemisLaserShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/ArtemisLaserShader", AssetRequestMode.ImmediateLoad).Value;
ExobladeSlashShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/ExobladeSlashShader", AssetRequestMode.ImmediateLoad).Value;
ExobladePierceShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/ExobladePierceShader", AssetRequestMode.ImmediateLoad).Value;
BaseFusableParticleEdgeShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/ParticleFusion/BaseFusableParticleEdgeShader", AssetRequestMode.ImmediateLoad).Value;
AdditiveFusableParticleEdgeShader = CalamityMod.Instance.Assets.Request<Effect>("Effects/ParticleFusion/AdditiveFusableParticleEdgeShader", AssetRequestMode.ImmediateLoad).Value;
@@ -114,6 +116,7 @@ namespace CalamityMod.Effects
GameShaders.Misc["CalamityMod:PrimitiveDrawer"] = new MiscShaderData(new Ref<Effect>(BasicPrimitiveShader), "TrailPass");
GameShaders.Misc["CalamityMod:ArtemisLaser"] = new MiscShaderData(new Ref<Effect>(ArtemisLaserShader), "TrailPass");
GameShaders.Misc["CalamityMod:ExobladeSlash"] = new MiscShaderData(new Ref<Effect>(ExobladeSlashShader), "TrailPass");
GameShaders.Misc["CalamityMod:ExobladePierce"] = new MiscShaderData(new Ref<Effect>(ExobladePierceShader), "PiercePass");
GameShaders.Misc["CalamityMod:BaseFusableParticleEdge"] = new MiscShaderData(new Ref<Effect>(BaseFusableParticleEdgeShader), "ParticlePass");
GameShaders.Misc["CalamityMod:AdditiveFusableParticleEdge"] = new MiscShaderData(new Ref<Effect>(AdditiveFusableParticleEdgeShader), "ParticlePass");
+72
View File
@@ -0,0 +1,72 @@
sampler uImage0 : register(s0);
sampler uImage1 : register(s1);
sampler uImage2 : register(s2);
float3 uColor;
float3 uSecondaryColor;
float3 fireColor;
float uOpacity;
float uSaturation;
float uRotation;
float uTime;
float4 uSourceRect;
float2 uWorldPosition;
float uDirection;
float3 uLightSource;
float2 uImageSize0;
float2 uImageSize1;
float2 uImageSize2;
matrix uWorldViewProjection;
float4 uShaderSpecificData;
bool flipped;
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;
}
float InverseLerp(float from, float to, float x)
{
return saturate((x - from) / (to - from));
}
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
float4 color = input.Color;
float2 coords = input.TextureCoordinates;
float bloomOpacity = pow(sin(coords.y * 3.141), 5.6);
float noise = tex2D(uImage1, coords * 3 - float2(uTime * 2.44, 0));
float brightnessStreak = tex2D(uImage2, coords * float2(2, 1) - float2(uTime * 1.61, 0)) + noise * bloomOpacity;
float4 energyColor = float4(lerp(uColor, uSecondaryColor, noise), 1);
return (energyColor * bloomOpacity + brightnessStreak * bloomOpacity) * color.a * pow(1 - coords.x, 1.6);
}
technique Technique1
{
pass PiercePass
{
VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
Binary file not shown.
+2 -6
View File
@@ -54,14 +54,10 @@ float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
float4 color = input.Color;
float2 coords = input.TextureCoordinates;
float timeDirection = -1;
if (flipped)
{
timeDirection = 1;
coords.y = 1 - coords.y;
}
float2 noiseCoords = coords * float2(0.5, 3) - float2(uTime * timeDirection * 0.45, 0);
float2 noiseCoords = coords * float2(0.5, 3) - float2(uTime * 0.45, 0);
noiseCoords.x = sin(noiseCoords.x * 5.4) * 0.5 + 0.5;
float noise = tex2D(uImage1, noiseCoords).r;
float noise2 = pow(tex2D(uImage1, noiseCoords * 2.2).r, 1.6);
@@ -76,7 +72,7 @@ float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
color = lerp(color, float4(uSecondaryColor, 1), darkColorWeight);
// Create a fire streak.
float fireColorWeight = InverseLerp(0.3, 0, coords.y) * pow(1 - coords.x, 0.5);
float fireColorWeight = InverseLerp(0.3, 0, coords.y) * pow(1 - coords.x, 1.56);
color = lerp(color, float4(fireColor, 1), fireColorWeight);
float4 noiseColor = color * opacity * (noise3 * 2.4 + 2.4);
Binary file not shown.
+3 -3
View File
@@ -1,7 +1,5 @@
using CalamityMod.Items.Materials;
using CalamityMod.Projectiles.Melee;
using CalamityMod.Tiles.Furniture.CraftingStations;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
@@ -16,6 +14,8 @@ namespace CalamityMod.Items.Weapons.Melee
public const float NotTrueMeleeDamagePenalty = 0.67f;
public const float LungeSpeed = 23.5f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Exoblade");
@@ -31,7 +31,7 @@ namespace CalamityMod.Items.Weapons.Melee
{
Item.width = 80;
Item.height = 114;
Item.damage = 1000;
Item.damage = 1776;
Item.useStyle = ItemUseStyleID.Swing;
Item.useTime = 49;
Item.useAnimation = 49;
+103 -41
View File
@@ -14,6 +14,8 @@ using CalamityMod.DataStructures;
using System.Linq;
using static CalamityMod.CalamityUtils;
using CalamityMod.Sounds;
using CalamityMod.Items.Weapons.Typeless;
using CalamityMod.Items.Weapons.DraedonsArsenal;
namespace CalamityMod.Projectiles.Melee
{
@@ -30,13 +32,15 @@ namespace CalamityMod.Projectiles.Melee
public PrimitiveTrail SlashDrawer = null;
public PrimitiveTrail PierceAfterimageDrawer = null;
public SwingState CurrentState;
public ref float ChargeTime => ref Projectile.ai[0];
public ref float GeneralTime => ref Projectile.ai[1];
public ref float VerticalStretchFactor => ref Projectile.localAI[0];
public ref float EnergyFormInterpolant => ref Projectile.localAI[0];
public ref float SwingDirection => ref Projectile.localAI[1];
@@ -48,7 +52,7 @@ namespace CalamityMod.Projectiles.Melee
public const float EndingSwingRotation = StartingSwingRotation + MathHelper.TwoPi - 0.33f;
// Starts at 0.27 and reels back.
public static CurveSegment Anticipation => new(EasingType.PolyInOut, 0f, 0.27f, -0.27f);
public static CurveSegment Anticipation => new(EasingType.PolyOut, 0f, 0.27f, -0.27f, 2);
public static CurveSegment SlashWait => new(EasingType.Linear, 0.37f, 0f, 0f);
@@ -56,7 +60,7 @@ namespace CalamityMod.Projectiles.Melee
public static CurveSegment Slash => new(EasingType.PolyOut, 0.51f, 0f, 1f);
// Manual easing code handles this, due to a 0-1 clamp within the piecewise curve function generator.
public static CurveSegment HoldBladeInPlace => new(EasingType.Linear, 0.7f, 1f, 0f);
public static CurveSegment HoldBladeInPlace => new(EasingType.PolyOut, 0.7f, 1f, 0.27f, 5);
public override string Texture => "CalamityMod/Items/Weapons/Melee/Exoblade";
@@ -117,11 +121,15 @@ namespace CalamityMod.Projectiles.Melee
Projectile.scale = 0f;
Projectile.Opacity = 0f;
EnergyFormInterpolant = 0f;
switch (CurrentState)
{
case SwingState.Swinging:
DoBehavior_Swinging();
break;
case SwingState.BonkDash:
DoBehavior_BonkDash();
break;
default:
Direction = Owner.direction;
Projectile.oldRot = new float[Projectile.oldRot.Length];
@@ -133,9 +141,7 @@ namespace CalamityMod.Projectiles.Melee
Owner.heldProj = Projectile.whoAmI;
// Decide the arm rotation for the owner.
float armRotation = Projectile.rotation + MathHelper.Pi;
if (Direction == -1)
armRotation += MathHelper.PiOver2;
float armRotation = Projectile.rotation + MathHelper.Pi + MathHelper.PiOver2;
if (CurrentState == SwingState.Default)
armRotation = 0f;
@@ -170,16 +176,10 @@ namespace CalamityMod.Projectiles.Melee
Projectile.oldRot = new float[Projectile.oldRot.Length];
// Decide the swing direction.
Projectile.rotation = MathHelper.Lerp(StartingSwingRotation, EndingSwingRotation, swingCompletion);
float returnToAnticiation = (float)Math.Pow(Utils.GetLerpValue(0.8f, 1f, directionalSwingCompletion, true), 2D);
Projectile.rotation = Projectile.rotation.AngleLerp(MathHelper.Lerp(StartingSwingRotation, EndingSwingRotation, 0.27f), returnToAnticiation);
Projectile.rotation = Projectile.rotation * Direction - MathHelper.PiOver4;
Projectile.rotation = MathHelper.Lerp(StartingSwingRotation, EndingSwingRotation, swingCompletion) * Direction - MathHelper.PiOver4;
if (Direction == -1)
Projectile.rotation -= MathHelper.PiOver2;
VerticalStretchFactor = Utils.Remap(swingCompletion, 0f, 0.5f, 0f, 0.4f);
// Decide the scale of the sword.
Projectile.scale = 1f;
if (!LMBUse)
@@ -199,10 +199,48 @@ namespace CalamityMod.Projectiles.Melee
Projectile.Opacity = Projectile.scale;
}
public void DoBehavior_BonkDash()
{
Owner.mount?.Dismount(Owner);
// Do the dash.
if (Owner.itemAnimation > Owner.itemAnimationMax * 0.6f)
{
if (Owner.itemAnimation == (int)(Owner.itemAnimationMax * 0.6f) + 1)
SoundEngine.PlaySound(CommonCalamitySounds.ELRFireSound, Projectile.Center);
Projectile.oldPos = new Vector2[Projectile.oldPos.Length];
if (Main.myPlayer == Projectile.owner)
{
Direction = Owner.direction;
Projectile.velocity = Projectile.SafeDirectionTo(Main.MouseWorld);
Owner.ChangeDir((Projectile.velocity.X > 0f).ToDirectionInt());
Projectile.netSpam = 0;
Projectile.netUpdate = true;
}
}
else
Owner.velocity = Projectile.velocity * Exoblade.LungeSpeed * 1.6f;
if (Owner.itemAnimation == 1)
{
Owner.itemAnimation = 0;
DecideCurrentState();
}
// Decide the scale and opacty of the sword.
Projectile.scale = 1f;
Projectile.Opacity = 1f;
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver4 * Direction;
float exactSwingCompletion = 1f - Owner.itemAnimation / (float)Owner.itemAnimationMax;
EnergyFormInterpolant = Utils.GetLerpValue(0f, 0.32f, exactSwingCompletion, true) * Utils.GetLerpValue(1f, 0.85f, exactSwingCompletion, true);
}
public void DecideCurrentState()
{
// Reset the state of the weapon if the player stops using it. This cannot reset a dash.
if (Owner.itemAnimation <= 0 && CurrentState != SwingState.BonkDash)
// Reset the state of the weapon if the player stops using it.
if (Owner.itemAnimation <= 0)
{
Owner.itemAnimation = 0;
CurrentState = SwingState.Default;
@@ -211,14 +249,13 @@ namespace CalamityMod.Projectiles.Melee
// Switch to the swing state as necessary. This cannot happen while channeling or dashing.
if (CurrentState == 0f && !RMBChannel && Owner.itemAnimation > 0)
CurrentState = SwingState.Swinging;
// Switch to the dash charge state. This can only be done while in the default state.
if (CurrentState == 0f && Owner.itemAnimation > 0)
{
Owner.fallStart = (int)(Owner.position.Y / 16f);
if (CurrentState != SwingState.BonkDash)
{
SoundEngine.PlaySound(SoundID.DD2_BookStaffCast, Owner.Center);
CurrentState = SwingState.BonkDash;
Projectile.netUpdate = true;
}
@@ -229,6 +266,10 @@ namespace CalamityMod.Projectiles.Melee
public Color SlashColorFunction(float completionRatio) => Color.Lime * Utils.GetLerpValue(0.9f, 0.4f, completionRatio, true) * Projectile.Opacity;
public float PierceWidthFunction(float completionRatio) => Utils.GetLerpValue(0f, 0.2f, completionRatio, true) * Projectile.scale * 50f;
public Color PierceColorFunction(float completionRatio) => Color.Lime * EnergyFormInterpolant * Projectile.Opacity;
public IEnumerable<Vector2> GenerateSlashPoints()
{
List<Vector2> result = new();
@@ -254,13 +295,26 @@ namespace CalamityMod.Projectiles.Melee
return result;
}
// TODO -- Split draw logic into distinct methods.
public override bool PreDraw(ref Color lightColor)
{
if (Projectile.Opacity <= 0f)
return false;
// Initialize the trail drawer.
// Initialize the primitives drawers.
SlashDrawer ??= new(SlashWidthFunction, SlashColorFunction, null, GameShaders.Misc["CalamityMod:ExobladeSlash"]);
PierceAfterimageDrawer ??= new(PierceWidthFunction, PierceColorFunction, null, GameShaders.Misc["CalamityMod:ExobladePierce"]);
float rotation = Projectile.rotation;
Vector2 origin = Projectile.Size * new Vector2(0.5f, 1f);
Vector2 drawPosition = Projectile.Center + Projectile.rotation.ToRotationVector2() * Projectile.scale * 32f - Main.screenPosition;
if (Direction == -1)
rotation += MathHelper.Pi;
var texture = ModContent.Request<Texture2D>(Texture).Value;
Color bladeColor = Color.White;
bladeColor = Color.Lerp(bladeColor, Color.Lerp(Color.Cyan, Color.Lime, 0.5f) with { A = 0 }, EnergyFormInterpolant);
bladeColor *= Projectile.Opacity;
Main.EntitySpriteDraw(texture, drawPosition, null, bladeColor, rotation, origin, Projectile.scale, Direction == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
// Draw the zany slash effect.
Main.spriteBatch.EnterShaderRegion();
@@ -274,32 +328,20 @@ namespace CalamityMod.Projectiles.Melee
GameShaders.Misc["CalamityMod:ExobladeSlash"].Apply();
if (CurrentState == SwingState.Swinging)
SlashDrawer.Draw(GenerateSlashPoints(), Projectile.Center - Main.screenPosition, 94);
SlashDrawer.Draw(GenerateSlashPoints(), Projectile.Center - Main.screenPosition, 95);
Main.spriteBatch.EnterShaderRegion();
var texture = ModContent.Request<Texture2D>(Texture).Value;
CalculatePerspectiveMatricies(out Matrix viewMatrix, out Matrix projectionMatrix);
GameShaders.Misc["CalamityMod:LinearTransformation"].UseColor(Main.hslToRgb(0.95f, 0.85f, 0.5f));
GameShaders.Misc["CalamityMod:LinearTransformation"].UseOpacity(0f);
GameShaders.Misc["CalamityMod:LinearTransformation"].Shader.Parameters["uWorldViewProjection"].SetValue(viewMatrix * projectionMatrix);
GameShaders.Misc["CalamityMod:LinearTransformation"].Shader.Parameters["localMatrix"].SetValue(new Matrix()
{
M11 = 1f,
M12 = 0f,
M21 = 0f,
M22 = 1f + VerticalStretchFactor * 0.4f,
});
GameShaders.Misc["CalamityMod:LinearTransformation"].Apply();
float rotation = Projectile.rotation;
Vector2 origin = Projectile.Size * new Vector2(0.5f, 1f);
Vector2 drawPosition = Projectile.Center + Projectile.rotation.ToRotationVector2() * Projectile.scale * 32f - Main.screenPosition;
if (Direction == -1)
rotation += MathHelper.Pi;
Main.EntitySpriteDraw(texture, drawPosition, null, Projectile.GetAlpha(Color.White), rotation, origin, Projectile.scale, Direction == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
Main.spriteBatch.ExitShaderRegion();
Vector2 trailOffset = (Projectile.rotation - Direction * MathHelper.PiOver4).ToRotationVector2() * 98f + Projectile.Size * 0.5f - Main.screenPosition;
GameShaders.Misc["CalamityMod:ExobladePierce"].SetShaderTexture(ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/EternityStreak"));
GameShaders.Misc["CalamityMod:ExobladePierce"].UseImage2("Images/Extra_189");
GameShaders.Misc["CalamityMod:ExobladePierce"].UseColor(Color.Cyan);
GameShaders.Misc["CalamityMod:ExobladePierce"].UseSecondaryColor(Color.Lime);
GameShaders.Misc["CalamityMod:ExobladePierce"].Apply();
if (CurrentState == SwingState.BonkDash)
PierceAfterimageDrawer.Draw(Projectile.oldPos.Take(31), trailOffset, 53);
Main.spriteBatch.EnterShaderRegion();
return false;
}
@@ -309,6 +351,26 @@ namespace CalamityMod.Projectiles.Melee
ItemLoader.OnHitNPC(Owner.ActiveItem(), Owner, target, damage, knockback, crit);
NPCLoader.OnHitByItem(target, Owner, Owner.ActiveItem(), damage, knockback, crit);
PlayerLoader.OnHitNPC(Owner, Owner.ActiveItem(), target, damage, knockback, crit);
if (CurrentState == SwingState.BonkDash && Owner.itemAnimation < Owner.itemAnimationMax * 0.6f)
{
Owner.itemAnimation = 0;
Owner.velocity = Owner.SafeDirectionTo(target.Center) * -11.5f;
SoundEngine.PlaySound(PlasmaGrenade.ExplosionSound, target.Center);
SoundEngine.PlaySound(YanmeisKnife.HitSound, target.Center);
if (Main.myPlayer == Projectile.owner)
{
for (int i = 0; i < 5; i++)
{
int slash = Projectile.NewProjectile(Projectile.GetSource_FromAI(), target.Center, Projectile.velocity * 0.1f, ModContent.ProjectileType<ExobeamSlashCreator>(), Projectile.damage * 2, 0f, Projectile.owner, target.whoAmI);
if (Main.projectile.IndexInRange(slash))
Main.projectile[slash].timeLeft -= i * 4;
}
}
DecideCurrentState();
}
}
public override bool? CanDamage() => CurrentState != SwingState.Default;
+1 -1
View File
@@ -319,7 +319,7 @@ namespace CalamityMod
start -= Main.screenPosition;
end -= Main.screenPosition;
Texture2D line = ModContent.Request<Texture2D>("InfernumMode/ExtraTextures/Line").Value;
Texture2D line = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/Line").Value;
float rotation = (end - start).ToRotation();
Vector2 scale = new Vector2(Vector2.Distance(start, end) / line.Width, width);