104 lines
3.0 KiB
C#
104 lines
3.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using ReLogic.Content;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Graphics.Metaballs
|
|
{
|
|
public class GalaxyMetaball : Metaball
|
|
{
|
|
public class CosmicParticle
|
|
{
|
|
public float Size;
|
|
|
|
public Vector2 Velocity;
|
|
|
|
public Vector2 Center;
|
|
|
|
public CosmicParticle(Vector2 center, Vector2 velocity, float size)
|
|
{
|
|
Center = center;
|
|
Velocity = velocity;
|
|
Size = size;
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
Center += Velocity;
|
|
Velocity *= 0.96f;
|
|
Size *= 0.91f;
|
|
}
|
|
}
|
|
|
|
public static Asset<Texture2D> LayerAsset
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
public static List<CosmicParticle> Particles
|
|
{
|
|
get;
|
|
private set;
|
|
} = new();
|
|
|
|
public override bool AnythingToDraw => Particles.Any();
|
|
|
|
public override IEnumerable<Texture2D> Layers
|
|
{
|
|
get
|
|
{
|
|
yield return LayerAsset.Value;
|
|
}
|
|
}
|
|
|
|
public override MetaballDrawLayer DrawContext => MetaballDrawLayer.BeforeNPCs;
|
|
|
|
public override Color EdgeColor => Color.Lerp(Color.DarkBlue, Color.Black, 0.75f);
|
|
|
|
public override void Load()
|
|
{
|
|
if (Main.netMode == NetmodeID.Server)
|
|
return;
|
|
|
|
// Load the layer asset wrapper.
|
|
LayerAsset = ModContent.Request<Texture2D>($"CalamityMod/Graphics/Metaballs/StreamGougeLayer", AssetRequestMode.ImmediateLoad);
|
|
}
|
|
|
|
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 void SpawnParticle(Vector2 position, Vector2 velocity, float size) =>
|
|
Particles.Add(new(position, velocity, size));
|
|
|
|
// Make the texture scroll.
|
|
public override Vector2 CalculateManualOffsetForLayer(int layerIndex)
|
|
{
|
|
return Vector2.UnitX * Main.GlobalTimeWrappedHourly * 0.037f;
|
|
}
|
|
|
|
public override void DrawInstances()
|
|
{
|
|
Texture2D tex = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/BasicCircle").Value;
|
|
|
|
foreach (CosmicParticle particle in Particles)
|
|
{
|
|
Vector2 drawPosition = particle.Center - Main.screenPosition;
|
|
Vector2 origin = tex.Size() * 0.5f;
|
|
Vector2 scale = Vector2.One * particle.Size / tex.Size();
|
|
Main.spriteBatch.Draw(tex, drawPosition, null, Color.White, 0f, origin, scale, SpriteEffects.None, 0f);
|
|
}
|
|
}
|
|
}
|
|
}
|