100 lines
5.2 KiB
C#
100 lines
5.2 KiB
C#
using CalamityMod.Particles;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.ModLoader;
|
|
using static Terraria.ModLoader.ModContent;
|
|
|
|
namespace CalamityMod.Projectiles.Melee
|
|
{
|
|
public class DecaysRetortDash : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Melee";
|
|
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
|
|
public Player Owner => Main.player[Projectile.owner];
|
|
public float Timer => 20 - Projectile.timeLeft;
|
|
|
|
public Vector2 DashStart;
|
|
public Vector2 DashEnd;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
}
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.DamageType = DamageClass.Melee;
|
|
Projectile.width = Projectile.height = 8;
|
|
Projectile.tileCollide = false;
|
|
Projectile.friendly = true;
|
|
Projectile.penetrate = -1;
|
|
Projectile.usesLocalNPCImmunity = true;
|
|
Projectile.localNPCHitCooldown = 60;
|
|
Projectile.timeLeft = 20;
|
|
}
|
|
|
|
public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox)
|
|
{
|
|
return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), DashStart, DashEnd);
|
|
}
|
|
|
|
public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers)
|
|
{
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
Vector2 sparkSpeed = target.DirectionTo(Owner.Center).RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4)) * 9f;
|
|
Particle Spark = new CritSpark(target.Center, sparkSpeed, Color.White, Color.Crimson, 1f + Main.rand.NextFloat(0, 1f), 30, 0.4f, 0.6f);
|
|
GeneralParticleHandler.SpawnParticle(Spark);
|
|
}
|
|
}
|
|
public override bool PreDraw(ref Color lightColor) //OMw to reuse way too much code from the entangling vines
|
|
{
|
|
Main.spriteBatch.End();
|
|
Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
|
|
|
|
Texture2D chainTex = Request<Texture2D>("CalamityMod/Projectiles/Melee/MendedBiomeBlade_DecaysRetortDash").Value;
|
|
|
|
Vector2 Shake = Projectile.timeLeft < 15 ? Vector2.Zero : Vector2.One.RotatedByRandom(MathHelper.TwoPi) * (15 - Projectile.timeLeft / 5f) * 0.5f;
|
|
|
|
int dist = (int)Vector2.Distance(DashEnd, DashStart) / 16;
|
|
Vector2[] Nodes = new Vector2[dist + 1];
|
|
Nodes[0] = DashStart;
|
|
Nodes[dist] = DashEnd;
|
|
|
|
for (int i = 1; i < dist + 1; i++)
|
|
{
|
|
Vector2 positionAlongLine = Vector2.Lerp(DashStart, DashEnd, i / (float)dist); //Get the position of the segment along the line
|
|
|
|
Nodes[i] = positionAlongLine + Shake * (float)Math.Sin(i / (float)dist * MathHelper.PiOver2);
|
|
|
|
float rotation = (Nodes[i] - Nodes[i - 1]).ToRotation() - MathHelper.PiOver2; //Calculate rotation based on direction from last point
|
|
float yScale = Vector2.Distance(Nodes[i], Nodes[i - 1]) / chainTex.Height; //Calculate how much to squash/stretch for smooth chain based on distance between points
|
|
float xScale = (i / (float)dist) * 5f;
|
|
Vector2 scale = new Vector2(xScale, yScale);
|
|
|
|
float opacity = MathHelper.Clamp((float)Math.Sin(i / (float)dist * MathHelper.PiOver2) - (i / (float)dist * ((20f - Projectile.timeLeft) / 25f)), 0f, 1f);
|
|
|
|
Vector2 origin = new Vector2(chainTex.Width / 2, chainTex.Height); //Draw from center bottom of texture
|
|
Main.EntitySpriteDraw(chainTex, Nodes[i] - Main.screenPosition, null, Color.Crimson * opacity, rotation, origin, scale, SpriteEffects.None, 0);
|
|
}
|
|
|
|
Texture2D sparkTexture = Request<Texture2D>("CalamityMod/Particles/CritSpark").Value;
|
|
Texture2D bloomTexture = Request<Texture2D>("CalamityMod/Particles/BloomCircle").Value;
|
|
//Ajust the bloom's texture to be the same size as the star's
|
|
float properBloomSize = (float)sparkTexture.Width / (float)bloomTexture.Height;
|
|
|
|
float bump = (float)Math.Sin(((20f - Projectile.timeLeft) / 20f) * MathHelper.Pi);
|
|
float raise = (float)Math.Sin(((20f - Projectile.timeLeft) / 20f) * MathHelper.PiOver2);
|
|
Rectangle frame = new Rectangle(0, 0, 14, 14);
|
|
|
|
Main.EntitySpriteDraw(bloomTexture, DashEnd - Main.screenPosition, null, Color.Crimson * bump * 0.5f, 0, bloomTexture.Size() / 2f, bump * 6f * properBloomSize, SpriteEffects.None, 0);
|
|
Main.EntitySpriteDraw(sparkTexture, DashEnd - Main.screenPosition, frame, Color.Lerp(Color.White, Color.Crimson, raise) * bump, raise * MathHelper.TwoPi, frame.Size() / 2f, bump * 3f, SpriteEffects.None, 0);
|
|
|
|
//Back to normal
|
|
Main.spriteBatch.End();
|
|
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
|
|
return false;
|
|
}
|
|
}
|
|
}
|