45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Particles
|
|
{
|
|
public class BloodParticle2 : Particle
|
|
{
|
|
public Color InitialColor;
|
|
public override bool SetLifetime => true;
|
|
public override bool UseCustomDraw => true;
|
|
public override bool UseAdditiveBlend => true;
|
|
|
|
public override string Texture => "CalamityMod/Particles/Blood2";
|
|
|
|
public BloodParticle2(Vector2 relativePosition, Vector2 velocity, int lifetime, float scale, Color color)
|
|
{
|
|
Position = relativePosition;
|
|
Velocity = velocity;
|
|
Scale = scale;
|
|
Lifetime = lifetime;
|
|
Color = InitialColor = color;
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
Velocity *= 0.98f;
|
|
Color = Color.Lerp(InitialColor, Color.Transparent, (float)Math.Pow(LifetimeCompletion, 4D));
|
|
Rotation = Velocity.ToRotation();
|
|
}
|
|
|
|
public override void CustomDraw(SpriteBatch spriteBatch)
|
|
{
|
|
float brightness = (float)Math.Pow(Lighting.Brightness((int)(Position.X / 16f), (int)(Position.Y / 16f)), 0.15);
|
|
Texture2D texture = ModContent.Request<Texture2D>(Texture);
|
|
Rectangle frame = texture.Frame(1, 3, 0, (int)(LifetimeCompletion * 3f));
|
|
Vector2 origin = frame.Size() * 0.5f;
|
|
|
|
spriteBatch.Draw(texture, Position - Main.screenPosition, frame, Color * brightness, Rotation, origin, Scale, 0, 0f);
|
|
}
|
|
}
|
|
}
|