diff --git a/ExtraTextures/Miscellaneous/NuclearTorrent.png b/ExtraTextures/Miscellaneous/NuclearTorrent.png new file mode 100644 index 0000000000..14d160d3d5 Binary files /dev/null and b/ExtraTextures/Miscellaneous/NuclearTorrent.png differ diff --git a/ForegroundDrawing/LoopingTextures/LoopingTextureForeground.cs b/ForegroundDrawing/LoopingTextures/LoopingTextureForeground.cs new file mode 100644 index 0000000000..441b8de6c0 --- /dev/null +++ b/ForegroundDrawing/LoopingTextures/LoopingTextureForeground.cs @@ -0,0 +1,123 @@ +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); + } + } + } +} diff --git a/ForegroundDrawing/LoopingTextures/NuclearTorrentForeground.cs b/ForegroundDrawing/LoopingTextures/NuclearTorrentForeground.cs new file mode 100644 index 0000000000..fb0cce3351 --- /dev/null +++ b/ForegroundDrawing/LoopingTextures/NuclearTorrentForeground.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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 class NuclearTorrentForeground : LoopingTextureForeground + { + public override Vector2 ParallaxDepth => new Vector2(1f, 1f); + + public override float IntensityMaximum => 0.045f; + + public static List Raindrops = new List(); + + public class NuclearRaindrop + { + public Vector2 Position; + public Vector2 Velocity; + + public NuclearRaindrop(Vector2 pos, Vector2 vel) + { + Position = pos; + Velocity = vel; + } + + public void Update(NuclearRaindrop drop, NuclearTorrentForeground foreground) + { + drop.Position += drop.Velocity; + drop.Position -= Main.LocalPlayer.velocity; + + drop.Velocity = new Vector2(0, 20).RotatedBy(-Main.windSpeedCurrent); + + if (drop.Position.Y > Main.screenHeight + 200) + { + RemoveDrop(drop); + } + } + + public void Draw(NuclearRaindrop drop, NuclearTorrentForeground foreground) + { + Asset tex = ModContent.Request("CalamityMod/ForegroundDrawing/LoopingTextures/NuclearTorrentRaindrop"); + + float intensity = foreground.Intensity / foreground.IntensityMaximum / 4f; + + Main.EntitySpriteDraw(tex.Value, drop.Position, tex.Frame(), Color.White.MultiplyRGBA(new Color(intensity, intensity, intensity, intensity)), Vector2.Zero.AngleTo(drop.Velocity) - MathHelper.ToRadians(90f), tex.Size() / 2, new Vector2(1f, 4f), SpriteEffects.None); + } + } + + public static void RemoveDrop(NuclearRaindrop drop) + { + Raindrops.Remove(drop); + } + + public override bool DoesThisShow() => NPC.CountNPCS(ModContent.NPCType()) > 0 && Main.LocalPlayer.Calamity().ZoneSulphur; + + public override void Update() + { + if (NPC.CountNPCS(ModContent.NPCType()) > 0) + { + int duke = NPC.FindFirstNPC(ModContent.NPCType()); + + Main.windSpeedCurrent = MathHelper.Lerp(Main.windSpeedCurrent, MathHelper.ToRadians(50f), 0.005f); + + foreach (Rain rain in Main.rain) + { + rain.velocity = new Vector2(0, 15).RotatedBy(-Main.windSpeedCurrent); + rain.rotation = Vector2.Zero.AngleTo(rain.velocity) + MathHelper.PiOver2; + } + } + + NuclearRaindrop dr = new NuclearRaindrop(new Vector2(Main.screenWidth / 2f, -100) + new Vector2(Main.rand.NextFloat(-Main.screenWidth, Main.screenWidth), -Main.screenWidth * 0.65f).RotatedBy(-Main.windSpeedCurrent), + new Vector2(0, 20).RotatedBy(-Main.windSpeedCurrent)); + Raindrops.Add(dr); + + for (int i = 0; i < Raindrops.Count; i++) + { + NuclearRaindrop drop = Raindrops[i]; + + drop.Update(drop, this); + } + } + + public override void PostDraw() + { + for (int i = 0; i < Raindrops.Count; i++) + { + NuclearRaindrop drop = Raindrops[i]; + + drop.Draw(drop, this); + } + } + } +} diff --git a/ForegroundDrawing/LoopingTextures/NuclearTorrentRaindrop.png b/ForegroundDrawing/LoopingTextures/NuclearTorrentRaindrop.png new file mode 100644 index 0000000000..428091be12 Binary files /dev/null and b/ForegroundDrawing/LoopingTextures/NuclearTorrentRaindrop.png differ