80 lines
2.5 KiB
C#
80 lines
2.5 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.Audio;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Projectiles.Ranged
|
|
{
|
|
public class ChargedBlast2 : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Ranged";
|
|
public override string Texture => "CalamityMod/Projectiles/LaserProj";
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 5;
|
|
Projectile.height = 5;
|
|
Projectile.friendly = true;
|
|
Projectile.DamageType = DamageClass.Ranged;
|
|
Projectile.penetrate = 3;
|
|
Projectile.MaxUpdates = 2;
|
|
Projectile.alpha = 255;
|
|
Projectile.timeLeft = 180;
|
|
Projectile.usesLocalNPCImmunity = true;
|
|
Projectile.localNPCHitCooldown = -1;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
if (Projectile.timeLeft < 60)
|
|
{
|
|
Projectile.alpha += 5;
|
|
if (Projectile.alpha >= 255)
|
|
Projectile.Kill();
|
|
}
|
|
else
|
|
{
|
|
if (Projectile.alpha > 0)
|
|
Projectile.alpha -= 25;
|
|
if (Projectile.alpha < 0)
|
|
Projectile.alpha = 0;
|
|
}
|
|
|
|
float lightScale = 1f - Projectile.alpha / 255f;
|
|
Projectile.ai[2] = lightScale;
|
|
Lighting.AddLight(Projectile.Center, 0f, 0.3f * lightScale, 0.7f * lightScale);
|
|
|
|
float beamLength = 30f;
|
|
float beamLengthGrowth = 0.5f;
|
|
Projectile.localAI[0] += beamLengthGrowth;
|
|
if (Projectile.localAI[0] > beamLength)
|
|
Projectile.localAI[0] = beamLength;
|
|
}
|
|
|
|
public override Color? GetAlpha(Color lightColor) => new Color(100, 100, 255, 0) * Projectile.ai[2];
|
|
|
|
public override bool PreDraw(ref Color lightColor) => Projectile.DrawBeam(100f, 3f, lightColor);
|
|
|
|
public override bool OnTileCollide(Vector2 oldVelocity)
|
|
{
|
|
SoundEngine.PlaySound(SoundID.Item10, Projectile.position);
|
|
|
|
Projectile.penetrate--;
|
|
if (Projectile.penetrate <= 0)
|
|
{
|
|
Projectile.Kill();
|
|
}
|
|
else
|
|
{
|
|
if (Projectile.velocity.X != oldVelocity.X)
|
|
Projectile.velocity.X = -oldVelocity.X;
|
|
if (Projectile.velocity.Y != oldVelocity.Y)
|
|
Projectile.velocity.Y = -oldVelocity.Y;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|