Basic sparkle particle

This commit is contained in:
IbanPlay committed 2022-01-06 21:56:17 +01:00
1 parent 47e91789a1
commit e24c9afe14
2 files changed
+33 -5

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

+33 -5
View File
@@ -1,27 +1,55 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Particles
{
public class GenericSparkle : Particle
{
public override string Texture => "CalamityMod/Particles/Sparkle";
public override bool UseAdditiveBlend => true;
public override bool UseCustomDraw => true;
public override bool SetLifetime => true;
public GenericSparkle(Vector2 position, Vector2 velocity, Color color, float scale, int lifeTime, float rotationSpeed = 1f)
private float Spin;
private float opacity;
private Color Bloom;
private Color LightColor => Bloom * opacity;
private float BloomScale;
public GenericSparkle(Vector2 position, Vector2 velocity, Color color, Color bloom, float scale, int lifeTime, float rotationSpeed = 1f, float bloomScale = 1f)
{
Position = position;
Velocity = velocity;
Color = color;
Bloom = bloom;
Scale = scale;
Lifetime = lifeTime;
Rotation = Main.rand.NextFloat(MathHelper.TwoPi);
Spin = rotationSpeed;
BloomScale = bloomScale;
}
public override void Update()
{
opacity = (float)Math.Sin(LifetimeCompletion * MathHelper.Pi);
Lighting.AddLight(Position, LightColor.R / 255f, LightColor.G / 255f, LightColor.B / 255f);
Velocity *= 0.95f;
Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f);
}
public override void CustomDraw(SpriteBatch spriteBatch)
{
Texture2D starTexture = GeneralParticleHandler.GetTexture(Type);
Texture2D bloomTexture = ModContent.GetTexture("CalamityMod/Particles/BloomCircle");
//Ajust the bloom's texture to be the same size as the star's
float properBloomSize = starTexture.Height / bloomTexture.Height;
spriteBatch.Draw(bloomTexture, Position - Main.screenPosition, null, Bloom * opacity * 0.5f, 0, bloomTexture.Size()/2f, Scale * BloomScale * properBloomSize, SpriteEffects.None, 0);
spriteBatch.Draw(starTexture, Position - Main.screenPosition, null, Color * opacity * 0.5f, Rotation + MathHelper.PiOver4, starTexture.Size() / 2f, Scale * 0.75f, SpriteEffects.None, 0);
spriteBatch.Draw(starTexture, Position - Main.screenPosition, null, Color * opacity, Rotation, starTexture.Size() / 2f, Scale, SpriteEffects.None, 0);
}
}
}