diff --git a/Graphics/Metaballs/BloodLayer.png b/Graphics/Metaballs/BloodLayer.png new file mode 100644 index 0000000000..ca6a3fdfb8 Binary files /dev/null and b/Graphics/Metaballs/BloodLayer.png differ diff --git a/Graphics/Metaballs/BloodMetaball.cs b/Graphics/Metaballs/BloodMetaball.cs new file mode 100644 index 0000000000..28457126f8 --- /dev/null +++ b/Graphics/Metaballs/BloodMetaball.cs @@ -0,0 +1,125 @@ +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Graphics.Metaballs +{ + public class BloodMetaball : Metaball + { + public class Particle + { + public float Size; + + public Vector2 Velocity; + + public Vector2 Center; + + public Texture2D TextureToUse = null; + + public float rotation = 0; + + public Vector2 Scale = Vector2.One; + + public float SizeScaling = 0.85f; + bool firstFrame = true; + public int CurrentFrame = 0; + public int MaxFrames = 1; + + public int ShrinkDelay = 45; + public int TimeAlive = 0; + public Particle(Vector2 center, Vector2 velocity, float size) + { + Center = center; + Velocity = velocity; + Size = size; + } + + public void Update() + { + TimeAlive++; + Center += Velocity; + Velocity *= 0.96f; + if (ShrinkDelay < TimeAlive) + Size *= SizeScaling; + firstFrame = false; + } + } + + //public override bool IgnoreFPS => true; + + public override bool FixedToScreen => false; + public static List Particles + { + get; + private set; + } = new(); + + public override bool AnythingToDraw => Particles.Any(); + public static Asset LayerAsset + { + get; + private set; + } + public override IEnumerable Layers + { + get + { + yield return LayerAsset.Value; + } + } + public override void Load() + { + if (Main.dedServ) + return; + + // Load the layer asset wrapper. + LayerAsset = ModContent.Request($"CalamityMod/Graphics/Metaballs/BloodLayer", AssetRequestMode.ImmediateLoad); + } + public override MetaballDrawLayer DrawContext => MetaballDrawLayer.BeforeProjectiles; + + public override Color EdgeColor => new Color(67, 17, 17); + + public override void Update() + { + // Update all particle instances. + // Once sufficiently small, they vanish. + for (int i = 0; i < Particles.Count; i++) + Particles[i].Update(); + Particles.RemoveAll(p => p.Size <= 2f); + } + + public static Particle SpawnParticle(Vector2 position, Vector2 velocity, float size) + { + Particle particle = new(position, velocity, size); + Particles.Add(particle); + + return particle; + } + + // Make the texture scroll. + public override Vector2 CalculateManualOffsetForLayer(int layerIndex) + { + return Vector2.UnitX * Main.GlobalTimeWrappedHourly * 0.0005f; + } + + public override void DrawInstances() + { + Texture2D tex = ModContent.Request("CalamityMod/ExtraTextures/BasicCircle").Value; + + foreach (Particle particle in Particles) + { + var texture2d = particle.TextureToUse ?? tex; + Vector2 drawPosition = particle.Center - Main.screenPosition; + var modScale = particle.Scale; + Vector2 scale = modScale * particle.Size / texture2d.Width; + var frame = texture2d.Frame(1, particle.MaxFrames, 0, particle.CurrentFrame); + Vector2 origin = frame.Size() * 0.5f; + Main.spriteBatch.Draw(texture2d, drawPosition, frame, Color.White, particle.rotation, origin, scale, SpriteEffects.None, 0f); + } + } + } +} diff --git a/Projectiles/Healing/BloodstoneHealOrb.cs b/Projectiles/Healing/BloodstoneHealOrb.cs index 6edd4ff6f5..357c86712c 100644 --- a/Projectiles/Healing/BloodstoneHealOrb.cs +++ b/Projectiles/Healing/BloodstoneHealOrb.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Graphics.Metaballs; using CalamityMod.Particles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -22,8 +23,8 @@ namespace CalamityMod.Projectiles.Healing public override void SetDefaults() { - Projectile.width = 8; - Projectile.height = 8; + Projectile.width = 16; + Projectile.height = 16; Projectile.ignoreWater = true; Projectile.alpha = 255; Projectile.penetrate = 1; @@ -35,20 +36,11 @@ namespace CalamityMod.Projectiles.Healing public override void AI() { - float particleSize = 0.9f + 0.15f * (float)Math.Cos(Main.GlobalTimeWrappedHourly % 60f * MathHelper.TwoPi); - if (Projectile.timeLeft <= 60) //Shrinks to nothing when projectile is nearing death - { - particleSize *= Projectile.timeLeft / 60f; - } - particleSize *= 8f; - Particle beam3 = new CustomSpark(Projectile.Center + Projectile.Size / 2f, -Projectile.velocity * 0.1f, "CalamityMod/Particles/PearlParticleGlow", false, 10, 0.05f * particleSize, Color.DarkRed, new Vector2(0.5f, 1), false, false, 0, false, false, 0f); - GeneralParticleHandler.SpawnParticle(beam3); - if (false && Main.rand.NextBool(8)) - { - Particle beam4 = new CustomSpark(Projectile.Center + Projectile.Size / 2f, Projectile.velocity * 0.1f, "CalamityMod/Particles/WaterFoam", false, 5, 0.01f * particleSize, Color.Red, new Vector2(1f, 1), true, false, Main.rand.NextFloat(-10, 10), false, false, 0f); - GeneralParticleHandler.SpawnParticle(beam4); - } + var p = BloodMetaball.SpawnParticle(Projectile.Center + Projectile.velocity, Main.rand.NextVector2Circular(-0.5f, -0.5f), Projectile.width); + p.SizeScaling = 0.75f; + p.ShrinkDelay = 1; + Projectile.scale = MathHelper.Lerp(1, 1, 0.65f); float maxDistance = 200f; if (spawnCooldown > 0)