using CalamityMod.NPCs.OldDuke; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.ModLoader; namespace CalamityMod.ForegroundDrawing.LoopingTextures { public abstract class LoopingTextureForeground : ModSystem { public virtual string Texture => "CalamityMod/ExtraTextures/Miscellaneous/NuclearTorrent"; /// /// How much the effect has moved. Increments by Speed. /// float Progress = 0f; /// /// The speed at which Progress is incremented every frame. /// public virtual float Speed => 60f; /// /// How opaque the visual is. Caps out at IntensityMaximum. /// public float Intensity = 0f; /// /// How opaque the visual can become before capping out. /// public virtual float IntensityMaximum => 0.15f; /// /// Current parallax. /// Vector2 Parallax = Vector2.Zero; /// /// Current parallax depth. /// public virtual Vector2 ParallaxDepth => Vector2.Zero; /// /// When true, the Intensity will increase until it caps out. If false it will decrease until it hits 0. /// /// Whether or not the visual is active. public virtual bool DoesThisShow() { return false; } public override void PostDrawTiles() { if (DoesThisShow()) { Intensity = MathHelper.Lerp(Intensity, IntensityMaximum, 0.1f); } else { Intensity = MathHelper.Lerp(Intensity, 0, 0.1f); } Intensity = MathHelper.Clamp(Intensity, 0f, 1f); Parallax += Main.LocalPlayer.velocity * ParallaxDepth; Progress += Speed; Main.spriteBatch.Begin(); Draw(); PostDraw(); Main.spriteBatch.End(); Update(); } public override void PostUpdateEverything() { Update(); } /// /// Extra drawing logic can be placed here. /// public virtual void PostDraw() { } /// /// Called every frame. Run behavior such as particle effects here. /// public virtual void Update() { } /// /// Override this to replace existing drawing logic. Only recommended if you know what you're doing. /// public virtual void Draw() { var tex = ModContent.Request(Texture); for (var i = -4; i < 14; i++) { float wid = tex.Width(); float hei = tex.Height(); var rect = new Rectangle(0, 0, (int)wid, (int)hei); var rot = -Main.WindForVisuals; var col = new Color(Intensity, Intensity, Intensity, 0f); Main.EntitySpriteDraw(tex.Value, new Vector2(Parallax.X % wid, 0).RotatedBy(rot) + new Vector2(tex.Width() * i, 0).RotatedBy(rot), rect, col, rot, new Vector2(0, (hei - Progress) % hei), 1, SpriteEffects.None); Main.EntitySpriteDraw(tex.Value, new Vector2(Parallax.X % wid, 0).RotatedBy(rot) + new Vector2(tex.Width() * i, -hei).RotatedBy(rot), rect, col, rot, new Vector2(0, (hei - Progress) % hei), 1, SpriteEffects.None); Main.EntitySpriteDraw(tex.Value, new Vector2(Parallax.X % wid, 0).RotatedBy(rot) + new Vector2(tex.Width() * i, -hei * 2).RotatedBy(rot), rect, col, rot, new Vector2(0, (hei - Progress) % hei), 1, SpriteEffects.None); } } } }