Squish collision effect

This commit is contained in:
Dominic authored and Cameron Ewell committed 2022-09-28 13:14:11 -04:00
1 parent dd45f8e485
commit d6701d539b
5 files changed
+59 -10

No files matched your search

+1 -1
View File
@@ -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))
@@ -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;
}
@@ -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)
+23 -6
View File
@@ -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<AtlasMunitionsAutocannon>(), 0, 0f, Projectile.owner);
Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Top + new Vector2(28f, 72f), Vector2.Zero, ModContent.ProjectileType<AtlasMunitionsDropPodUpper>(), 0, 0f, Projectile.owner);
Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Center + Vector2.UnitY * 10f, Vector2.Zero, ModContent.ProjectileType<AtlasMunitionsAutocannon>(), 0, 0f, Projectile.owner);
Projectile.NewProjectile(Projectile.GetSource_FromAI(), Projectile.Top + Vector2.UnitY * 72f, Vector2.Zero, ModContent.ProjectileType<AtlasMunitionsDropPodUpper>(), 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<Texture2D>("CalamityMod/Projectiles/Summon/AtlasMunitionsDropPodGlow").Value;
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
Texture2D glowmask = ModContent.Request<Texture2D>("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;
}
}
}
@@ -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<Texture2D>(Texture).Value;