add beam wand (thanks lexy)
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
using Terraria.GameContent;
|
||||
|
||||
namespace ForgottenWawiTech.Content.Projectiles
|
||||
{
|
||||
// Short-lived beam projectile emitted rapidly by BeamAttackWand.
|
||||
// Simple straight projectile with minor dust and fade-out.
|
||||
public class BeamAttackWandBeam : ModProjectile
|
||||
{
|
||||
private const int FrameCount = 3;
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
Main.projFrames[Type] = FrameCount; // 3 vertical frames
|
||||
}
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
Projectile.width = 28; // frame width
|
||||
Projectile.height = 28; // frame height
|
||||
Projectile.friendly = true;
|
||||
Projectile.penetrate = 1; // single hit per beam
|
||||
Projectile.timeLeft = 15; // very short duration
|
||||
Projectile.DamageType = DamageClass.Melee;
|
||||
Projectile.tileCollide = true;
|
||||
Projectile.light = 0.4f;
|
||||
Projectile.alpha = 40;
|
||||
}
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
// Frame animation: advance every 4 ticks for subtle flicker
|
||||
Projectile.frameCounter++;
|
||||
if (Projectile.frameCounter >= 4)
|
||||
{
|
||||
Projectile.frameCounter = 0;
|
||||
Projectile.frame = (Projectile.frame + 1) % FrameCount;
|
||||
}
|
||||
|
||||
// Slight acceleration forward for a snappy feel
|
||||
Projectile.velocity *= 1.02f;
|
||||
|
||||
// Simple fade: become more transparent near end
|
||||
if (Projectile.timeLeft < 6)
|
||||
Projectile.alpha += 25;
|
||||
|
||||
// Spawn light dust
|
||||
if (Main.rand.NextBool(3))
|
||||
{
|
||||
int d = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.PurpleTorch,
|
||||
Projectile.velocity.X * 0.2f, Projectile.velocity.Y * 0.2f, 150, default, 0.9f);
|
||||
Main.dust[d].noGravity = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnTileCollide(Vector2 oldVelocity)
|
||||
{
|
||||
// So beams feel crisp: slight bounce spark then die
|
||||
Projectile.timeLeft = 5;
|
||||
Projectile.velocity *= 0.4f;
|
||||
return false; // don't kill immediately; fade
|
||||
}
|
||||
|
||||
public override bool PreDraw(ref Color lightColor)
|
||||
{
|
||||
Texture2D tex = TextureAssets.Projectile[Type].Value;
|
||||
int frameHeight = tex.Height / FrameCount;
|
||||
Rectangle frameRect = new(0, frameHeight * Projectile.frame, tex.Width, frameHeight);
|
||||
Vector2 origin = new(tex.Width / 2f, frameHeight / 2f);
|
||||
float baseScale = 1f;
|
||||
float stretchX = 0.6f + Projectile.velocity.Length() / 30f; // elongate horizontally
|
||||
Color drawColor = Color.White * (1f - Projectile.alpha / 255f);
|
||||
|
||||
// Slight additive trail effect: draw faint previous frame positions
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Vector2 trailPos = Projectile.Center - Projectile.velocity * i * 0.8f;
|
||||
float trailAlpha = (0.4f - i * 0.12f) * (1f - Projectile.alpha / 255f);
|
||||
Main.EntitySpriteDraw(tex, trailPos - Main.screenPosition, frameRect,
|
||||
drawColor * trailAlpha, Projectile.rotation, origin,
|
||||
new Vector2(stretchX, baseScale), SpriteEffects.None);
|
||||
}
|
||||
|
||||
// Main frame (bright)
|
||||
Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, frameRect,
|
||||
drawColor, Projectile.rotation, origin,
|
||||
new Vector2(stretchX, baseScale), SpriteEffects.None);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user