From d6701d539bbb8a4c3dfd80948a46f6967cf3c711 Mon Sep 17 00:00:00 2001 From: Dominic Date: Mon, 26 Sep 2022 16:15:50 -0500 Subject: [PATCH] Squish collision effect --- Items/Weapons/Summon/AtlasMunitionsBeacon.cs | 2 +- .../Summon/AtlasMunitionsAutocannon.cs | 2 +- .../Summon/AtlasMunitionsAutocannonHeld.cs | 4 ++- Projectiles/Summon/AtlasMunitionsDropPod.cs | 29 +++++++++++++---- .../Summon/AtlasMunitionsLaserOverdrive.cs | 32 ++++++++++++++++++- 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/Items/Weapons/Summon/AtlasMunitionsBeacon.cs b/Items/Weapons/Summon/AtlasMunitionsBeacon.cs index fe37a660f2..f6c7902434 100644 --- a/Items/Weapons/Summon/AtlasMunitionsBeacon.cs +++ b/Items/Weapons/Summon/AtlasMunitionsBeacon.cs @@ -93,7 +93,7 @@ namespace CalamityMod.Items.Weapons.Summon { if (player.altFunctionUse != 2) { - position = Main.MouseWorld - Vector2.UnitY.RotatedByRandom(0.47f) * 1020f; + position = Main.MouseWorld - Vector2.UnitY * 1020f; velocity = (Main.MouseWorld - position).SafeNormalize(Vector2.UnitY) * Main.rand.NextFloat(9f, 10f); int p = Projectile.NewProjectile(source, position, velocity, type, damage, knockback, player.whoAmI, Main.MouseWorld.Y - 40f); if (Main.projectile.IndexInRange(p)) diff --git a/Projectiles/Summon/AtlasMunitionsAutocannon.cs b/Projectiles/Summon/AtlasMunitionsAutocannon.cs index 2ff64a8803..170e12ede8 100644 --- a/Projectiles/Summon/AtlasMunitionsAutocannon.cs +++ b/Projectiles/Summon/AtlasMunitionsAutocannon.cs @@ -55,7 +55,7 @@ namespace CalamityMod.Projectiles.Summon Projectile.netImportant = true; Projectile.sentry = true; Projectile.penetrate = -1; - Projectile.timeLeft = Projectile.SentryLifeTime; + Projectile.timeLeft = 90000; Projectile.DamageType = DamageClass.Summon; Projectile.Opacity = 0f; } diff --git a/Projectiles/Summon/AtlasMunitionsAutocannonHeld.cs b/Projectiles/Summon/AtlasMunitionsAutocannonHeld.cs index 5141452dd7..022e981ca1 100644 --- a/Projectiles/Summon/AtlasMunitionsAutocannonHeld.cs +++ b/Projectiles/Summon/AtlasMunitionsAutocannonHeld.cs @@ -274,11 +274,13 @@ namespace CalamityMod.Projectiles.Summon public void UpdateProjectileHeldVariables(Vector2 armPosition) { + // Update the cannon direction. if (Main.myPlayer == Projectile.owner) { - float interpolant = Utils.GetLerpValue(16f, 56f, Projectile.Distance(Main.MouseWorld), true); + float interpolant = Utils.GetLerpValue(16f, 56f, Projectile.Distance(Main.MouseWorld), true) * Utils.GetLerpValue(3f, 10f, MathHelper.Distance(Main.MouseWorld.X, Owner.Center.X), true); Vector2 oldVelocity = Projectile.velocity; Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.SafeDirectionTo(Main.MouseWorld), interpolant).SafeNormalize(Vector2.UnitX * Owner.direction); + Projectile.direction = (Projectile.velocity.X > 0f).ToDirectionInt(); Projectile.spriteDirection = Projectile.direction; if (Projectile.velocity != oldVelocity) diff --git a/Projectiles/Summon/AtlasMunitionsDropPod.cs b/Projectiles/Summon/AtlasMunitionsDropPod.cs index 541402513f..bd6cf5cb24 100644 --- a/Projectiles/Summon/AtlasMunitionsDropPod.cs +++ b/Projectiles/Summon/AtlasMunitionsDropPod.cs @@ -23,6 +23,8 @@ namespace CalamityMod.Projectiles.Summon set => Projectile.ai[1] = value.ToInt(); } + public ref float SquishFactor => ref Projectile.localAI[0]; + public const float Gravity = 1.1f; public const float MaxFallSpeed = 24f; @@ -52,6 +54,9 @@ namespace CalamityMod.Projectiles.Summon public override void AI() { + if (SquishFactor <= 0f) + SquishFactor = 1f; + if (Projectile.velocity.Y == 0f && !HasCollidedWithGround) { PerformGroundCollisionEffects(); @@ -59,6 +64,10 @@ namespace CalamityMod.Projectiles.Summon Projectile.netUpdate = true; } + // Undo squish effects. + SquishFactor = MathHelper.Lerp(SquishFactor, 1f, 0.08f); + + // Determine whether to collide with tiles. Projectile.tileCollide = Projectile.Bottom.Y >= TileCollisionYThreshold; // Calculate frames. @@ -80,8 +89,8 @@ namespace CalamityMod.Projectiles.Summon SoundEngine.PlaySound(ThanatosHead.VentSound, Projectile.Top); if (Main.netMode != NetmodeID.MultiplayerClient) { - Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center + new Vector2(28f, 10f), Vector2.Zero, ModContent.ProjectileType(), 0, 0f, Projectile.owner); - Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Top + new Vector2(28f, 72f), Vector2.Zero, ModContent.ProjectileType(), 0, 0f, Projectile.owner); + Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center + Vector2.UnitY * 10f, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, Projectile.owner); + Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Top + Vector2.UnitY * 72f, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, Projectile.owner); } } } @@ -97,13 +106,16 @@ namespace CalamityMod.Projectiles.Summon public void PerformGroundCollisionEffects() { + // Become squished. + SquishFactor = 1.4f; + // Mechanical Cart laser dust. Looks epic. int dustID = 182; int dustCount = 54; for (int i = 0; i < dustCount; i += 2) { float pairSpeed = Main.rand.NextFloat(0.5f, 16f); - Dust d = Dust.NewDustDirect(Projectile.BottomRight, 0, 0, dustID); + Dust d = Dust.NewDustDirect(Projectile.Bottom, 0, 0, dustID); d.velocity = Vector2.UnitX * pairSpeed; d.scale = 2.7f; d.noGravity = true; @@ -128,12 +140,17 @@ namespace CalamityMod.Projectiles.Summon public override bool OnTileCollide(Vector2 oldVelocity) => false; - public override void PostDraw(Color lightColor) + public override bool PreDraw(ref Color lightColor) { - Texture2D texture = ModContent.Request("CalamityMod/Projectiles/Summon/AtlasMunitionsDropPodGlow").Value; + Texture2D texture = ModContent.Request(Texture).Value; + Texture2D glowmask = ModContent.Request("CalamityMod/Projectiles/Summon/AtlasMunitionsDropPodGlow").Value; Rectangle frame = texture.Frame(1, Main.projFrames[Type], 0, Projectile.frame); Vector2 drawPosition = Projectile.Center - Main.screenPosition; - Main.EntitySpriteDraw(texture, drawPosition, frame, Color.White, Projectile.rotation, Projectile.Size * 0.5f, Projectile.scale, 0, 0); + Vector2 scale = Projectile.scale * new Vector2(SquishFactor, 1f / SquishFactor); + Vector2 origin = frame.Size() * new Vector2(0.5f, 0.5f / SquishFactor); + Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, scale, 0, 0); + Main.EntitySpriteDraw(glowmask, drawPosition, frame, Color.White, Projectile.rotation, origin, scale, 0, 0); + return false; } } } diff --git a/Projectiles/Summon/AtlasMunitionsLaserOverdrive.cs b/Projectiles/Summon/AtlasMunitionsLaserOverdrive.cs index 949ed32484..d2981f9557 100644 --- a/Projectiles/Summon/AtlasMunitionsLaserOverdrive.cs +++ b/Projectiles/Summon/AtlasMunitionsLaserOverdrive.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using System; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; @@ -48,6 +49,35 @@ namespace CalamityMod.Projectiles.Summon Projectile.velocity *= 1.026f; } + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + int dustCount = 32; + bool sideways = Main.rand.NextBool(8); + float generalAngularOffset = Main.rand.NextFloatDirection() * MathHelper.Pi / 24f; + if (sideways) + dustCount += 20; + + for (int i = 0; i < dustCount; i++) + { + float offsetAngle = MathHelper.TwoPi * i / dustCount; + + // Parametric equations for an asteroid. + float unitOffsetX = (float)Math.Pow(Math.Cos(offsetAngle), 3D); + float unitOffsetY = (float)Math.Pow(Math.Sin(offsetAngle), 3D); + + Vector2 puffDustVelocity = new Vector2(unitOffsetX, unitOffsetY) * 4.2f; + if (sideways) + puffDustVelocity = puffDustVelocity.RotatedBy(MathHelper.PiOver4) * 2f; + else + puffDustVelocity = puffDustVelocity.RotatedBy(generalAngularOffset); + + Dust magic = Dust.NewDustPerfect(target.Center, 182, puffDustVelocity); + magic.scale = 1.8f; + magic.fadeIn = 0.5f; + magic.noGravity = true; + } + } + public override bool PreDraw(ref Color lightColor) { Texture2D texture = ModContent.Request(Texture).Value;