diff --git a/Particles/Blood.png b/Particles/Blood.png new file mode 100644 index 0000000000..d123f8dc42 Binary files /dev/null and b/Particles/Blood.png differ diff --git a/Particles/Blood2.png b/Particles/Blood2.png new file mode 100644 index 0000000000..be02000dfc Binary files /dev/null and b/Particles/Blood2.png differ diff --git a/Particles/BloodParticle.cs b/Particles/BloodParticle.cs new file mode 100644 index 0000000000..8a8fe242de --- /dev/null +++ b/Particles/BloodParticle.cs @@ -0,0 +1,46 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class BloodParticle : Particle + { + public Color InitialColor; + public override bool SetLifetime => true; + public override bool UseCustomDraw => true; + public override bool UseAdditiveBlend => true; + + public override string Texture => "CalamityMod/Particles/Blood"; + + public BloodParticle(Vector2 relativePosition, Vector2 velocity, int lifetime, float scale, Color color) + { + Position = relativePosition; + Velocity = velocity; + Scale = scale; + Lifetime = lifetime; + Color = InitialColor = color; + } + + public override void Update() + { + Scale *= 0.98f; + Velocity.X *= 0.97f; + Velocity.Y = MathHelper.Clamp(Velocity.Y + 0.9f, -22f, 22f); + Color = Color.Lerp(InitialColor, Color.Transparent, (float)Math.Pow(LifetimeCompletion, 3D)); + Rotation = Velocity.ToRotation() + MathHelper.PiOver2; + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + float verticalStretch = Utils.InverseLerp(0f, 24f, Math.Abs(Velocity.Y), true) * 0.84f; + float brightness = (float)Math.Pow(Lighting.Brightness((int)(Position.X / 16f), (int)(Position.Y / 16f)), 0.15); + Vector2 scale = new Vector2(1f, verticalStretch + 1f) * Scale * 0.1f; + Texture2D texture = ModContent.GetTexture(Texture); + + spriteBatch.Draw(texture, Position - Main.screenPosition, null, Color * brightness, Rotation, texture.Size() * 0.5f, scale, 0, 0f); + } + } +} diff --git a/Particles/BloodParticle2.cs b/Particles/BloodParticle2.cs new file mode 100644 index 0000000000..500fdd6c7c --- /dev/null +++ b/Particles/BloodParticle2.cs @@ -0,0 +1,44 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class BloodParticle2 : Particle + { + public Color InitialColor; + public override bool SetLifetime => true; + public override bool UseCustomDraw => true; + public override bool UseAdditiveBlend => true; + + public override string Texture => "CalamityMod/Particles/Blood2"; + + public BloodParticle2(Vector2 relativePosition, Vector2 velocity, int lifetime, float scale, Color color) + { + Position = relativePosition; + Velocity = velocity; + Scale = scale; + Lifetime = lifetime; + Color = InitialColor = color; + } + + public override void Update() + { + Velocity *= 0.98f; + Color = Color.Lerp(InitialColor, Color.Transparent, (float)Math.Pow(LifetimeCompletion, 4D)); + Rotation = Velocity.ToRotation(); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + float brightness = (float)Math.Pow(Lighting.Brightness((int)(Position.X / 16f), (int)(Position.Y / 16f)), 0.15); + Texture2D texture = ModContent.GetTexture(Texture); + Rectangle frame = texture.Frame(1, 3, 0, (int)(LifetimeCompletion * 3f)); + Vector2 origin = frame.Size() * 0.5f; + + spriteBatch.Draw(texture, Position - Main.screenPosition, frame, Color * brightness, Rotation, origin, Scale, 0, 0f); + } + } +} diff --git a/Particles/ImpactParticle.cs b/Particles/ImpactParticle.cs new file mode 100644 index 0000000000..43728049c4 --- /dev/null +++ b/Particles/ImpactParticle.cs @@ -0,0 +1,40 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class ImpactParticle : Particle + { + public float AngularVelocity; + public override bool SetLifetime => true; + public override bool UseCustomDraw => true; + public override bool UseAdditiveBlend => true; + + public override string Texture => "CalamityMod/Projectiles/StarProj"; + + public ImpactParticle(Vector2 relativePosition, float angularVelocity, int lifetime, float scale, Color color) + { + Position = relativePosition; + Scale = scale; + AngularVelocity = angularVelocity; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Lifetime = lifetime; + Color = color; + } + + public override void Update() => Rotation += AngularVelocity; + + public override void CustomDraw(SpriteBatch spriteBatch) + { + float scaleFactor = CalamityUtils.Convert01To010(LifetimeCompletion) * 1.3f; + Vector2 scale = new Vector2(0.3f, 1f) * scaleFactor; + Texture2D texture = ModContent.GetTexture(Texture); + + spriteBatch.Draw(texture, Position - Main.screenPosition, null, Color, 0f, texture.Size() * 0.5f, scale, 0, 0f); + spriteBatch.Draw(texture, Position - Main.screenPosition, null, Color, Rotation, texture.Size() * 0.5f, scale, 0, 0f); + spriteBatch.Draw(texture, Position - Main.screenPosition, null, Color, -Rotation, texture.Size() * 0.5f, scale, 0, 0f); + } + } +} diff --git a/Particles/SparkParticle.cs b/Particles/SparkParticle.cs new file mode 100644 index 0000000000..280c905c45 --- /dev/null +++ b/Particles/SparkParticle.cs @@ -0,0 +1,48 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class SparkParticle : Particle + { + public Color InitialColor; + public override bool SetLifetime => true; + public override bool UseCustomDraw => true; + public override bool UseAdditiveBlend => true; + + public override string Texture => "CalamityMod/Projectiles/StarProj"; + + public SparkParticle(Vector2 relativePosition, Vector2 velocity, int lifetime, float scale, Color color) + { + Position = relativePosition; + Velocity = velocity; + Scale = scale; + Lifetime = lifetime; + Color = InitialColor = color; + } + + public override void Update() + { + Scale *= 0.95f; + Color = Color.Lerp(InitialColor, Color.Transparent, (float)Math.Pow(LifetimeCompletion, 3D)); + Velocity *= 0.95f; + if (Velocity.Length() < 12f) + { + Velocity.X *= 0.94f; + Velocity.Y += 0.25f; + } + Rotation = Velocity.ToRotation() + MathHelper.PiOver2; + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Vector2 scale = new Vector2(0.35f, 1.6f) * Scale; + Texture2D texture = ModContent.GetTexture(Texture); + + spriteBatch.Draw(texture, Position - Main.screenPosition, null, Color, Rotation, texture.Size() * 0.5f, scale, 0, 0f); + } + } +} diff --git a/Projectiles/Melee/ViolenceThrownProjectile.cs b/Projectiles/Melee/ViolenceThrownProjectile.cs index 0315288d26..1be6b26875 100644 --- a/Projectiles/Melee/ViolenceThrownProjectile.cs +++ b/Projectiles/Melee/ViolenceThrownProjectile.cs @@ -1,3 +1,4 @@ +using CalamityMod.Particles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; @@ -44,7 +45,7 @@ namespace CalamityMod.Projectiles.Melee if (Owner.channel) { HomeTowardsMouse(); - projectile.rotation += 0.35f / projectile.MaxUpdates; + projectile.rotation += 0.45f / projectile.MaxUpdates; } else { @@ -97,6 +98,78 @@ namespace CalamityMod.Projectiles.Melee Owner.itemAnimation = 2; } + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + if (Main.netMode != NetmodeID.Server) + { + // Play a splatter and impact sound. + Main.PlaySound(SoundID.DD2_CrystalCartImpact, projectile.Center); + + float damageInterpolant = Utils.InverseLerp(950f, 2000f, damage, true); + float impactAngularVelocity = MathHelper.Lerp(0.08f, 0.2f, damageInterpolant); + float impactParticleScale = MathHelper.Lerp(0.6f, 1f, damageInterpolant); + impactAngularVelocity *= Main.rand.NextBool().ToDirectionInt() * Main.rand.NextFloat(0.75f, 1.25f); + + Color impactColor = Color.Lerp(Color.Silver, Color.Gold, Main.rand.NextFloat(0.5f)); + Vector2 impactPoint = Vector2.Lerp(projectile.Center, target.Center, 0.65f); + Vector2 bloodSpawnPosition = target.Center + Main.rand.NextVector2Circular(target.width, target.height) * 0.04f; + Vector2 splatterDirection = (projectile.Center - bloodSpawnPosition).SafeNormalize(Vector2.UnitY); + + // Emit blood if the target is organic. + if (target.Organic()) + { + Main.PlaySound(SoundID.NPCHit18, projectile.Center); + for (int i = 0; i < 6; i++) + { + int bloodLifetime = Main.rand.Next(22, 36); + float bloodScale = Main.rand.NextFloat(0.6f, 0.8f); + Color bloodColor = Color.Lerp(Color.Red, Color.DarkRed, Main.rand.NextFloat()); + bloodColor = Color.Lerp(bloodColor, new Color(51, 22, 94), Main.rand.NextFloat(0.65f)); + + if (Main.rand.NextBool(20)) + bloodScale *= 2f; + + Vector2 bloodVelocity = splatterDirection.RotatedByRandom(0.81f) * Main.rand.NextFloat(11f, 23f); + bloodVelocity.Y -= 12f; + BloodParticle blood = new BloodParticle(bloodSpawnPosition, bloodVelocity, bloodLifetime, bloodScale, bloodColor); + GeneralParticleHandler.SpawnParticle(blood); + } + for (int i = 0; i < 3; i++) + { + float bloodScale = Main.rand.NextFloat(0.2f, 0.33f); + Color bloodColor = Color.Lerp(Color.Red, Color.DarkRed, Main.rand.NextFloat(0.5f, 1f)); + Vector2 bloodVelocity = splatterDirection.RotatedByRandom(0.9f) * Main.rand.NextFloat(9f, 14.5f); + BloodParticle2 blood = new BloodParticle2(bloodSpawnPosition, bloodVelocity, 20, bloodScale, bloodColor); + GeneralParticleHandler.SpawnParticle(blood); + } + } + + // Emit sparks if the target is not organic. + else + { + for (int i = 0; i < 6; i++) + { + int sparkLifetime = Main.rand.Next(22, 36); + float sparkScale = Main.rand.NextFloat(0.8f, 1f) + damageInterpolant * 0.85f; + Color sparkColor = Color.Lerp(Color.Silver, Color.Gold, Main.rand.NextFloat(0.7f)); + sparkColor = Color.Lerp(sparkColor, Color.Orange, Main.rand.NextFloat()); + + if (Main.rand.NextBool(10)) + sparkScale *= 2f; + + Vector2 sparkVelocity = splatterDirection.RotatedByRandom(0.6f) * Main.rand.NextFloat(12f, 25f); + sparkVelocity.Y -= 6f; + SparkParticle spark = new SparkParticle(impactPoint, sparkVelocity, sparkLifetime, sparkScale, sparkColor); + GeneralParticleHandler.SpawnParticle(spark); + } + } + + // And create an impact point particle. + ImpactParticle impactParticle = new ImpactParticle(impactPoint, impactAngularVelocity, 20, impactParticleScale, impactColor); + GeneralParticleHandler.SpawnParticle(impactParticle); + } + } + internal float PrimitiveWidthFunction(float completionRatio) { float tipWidthFactor = MathHelper.SmoothStep(0f, 1f, Utils.InverseLerp(0.01f, 0.04f, completionRatio));