using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.MainMenu { public class CalamityMainMenu : ModMenu { public class Cinder { public int Time; public int Lifetime; public int IdentityIndex; public float Scale; public float Depth; public Color DrawColor; public Vector2 Velocity; public Vector2 Center; public Cinder(int lifetime, int identity, float depth, Color color, Vector2 startingPosition, Vector2 startingVelocity) { Lifetime = lifetime; IdentityIndex = identity; Depth = depth; DrawColor = color; Center = startingPosition; Velocity = startingVelocity; } } public static List Cinders { get; internal set; } = new(); public override string DisplayName => "Calamity Style"; public override Asset Logo => ModContent.Request("CalamityMod/MainMenu/Logo"); public override Asset SunTexture => ModContent.Request("CalamityMod/Backgrounds/BlankPixel"); public override Asset MoonTexture => ModContent.Request("CalamityMod/Backgrounds/BlankPixel"); public override int Music => CalamityMod.Instance.GetMusicFromMusicMod("Calamity") ?? MusicID.Title; public override ModSurfaceBackgroundStyle MenuBackgroundStyle => ModContent.GetInstance(); // Before drawing the logo, draw the entire Calamity background. This way, the typical parallax background is skipped entirely. public override bool PreDrawLogo(SpriteBatch spriteBatch, ref Vector2 logoDrawCenter, ref float logoRotation, ref float logoScale, ref Color drawColor) { Texture2D texture = ModContent.Request("CalamityMod/MainMenu/MenuBackground").Value; spriteBatch.Draw(texture, new Vector2(0f, 0f), null, Color.White, 0f, Vector2.Zero, (float)Main.screenWidth / texture.Width, SpriteEffects.None, 0f); static Color selectCinderColor() { if (Main.rand.NextBool(3)) return Color.Lerp(Color.DarkGray, Color.LightGray, Main.rand.NextFloat()); return Color.Lerp(Color.Red, Color.Yellow, Main.rand.NextFloat(0.9f)); } // Randomly add cinders. for (int i = 0; i < 5; i++) { if (Main.rand.NextBool(4)) { int lifetime = Main.rand.Next(200, 300); float depth = Main.rand.NextFloat(1.8f, 5f); Vector2 startingPosition = new Vector2(Main.screenWidth * Main.rand.NextFloat(-0.1f, 1.1f), Main.screenHeight * 1.05f); Vector2 startingVelocity = -Vector2.UnitY.RotatedBy(Main.rand.NextFloat(-0.9f, 0.9f)) * 4f; Color cinderColor = selectCinderColor(); Cinders.Add(new Cinder(lifetime, Cinders.Count, depth, cinderColor, startingPosition, startingVelocity)); } } // Update all cinders. for (int i = 0; i < Cinders.Count; i++) { Cinders[i].Scale = Utils.GetLerpValue(Cinders[i].Lifetime, Cinders[i].Lifetime / 3, Cinders[i].Time, true); Cinders[i].Scale *= MathHelper.Lerp(0.6f, 0.9f, Cinders[i].IdentityIndex % 6f / 6f); if (Cinders[i].IdentityIndex % 13 == 12) Cinders[i].Scale *= 2f; float flySpeed = MathHelper.Lerp(3.2f, 14f, Cinders[i].IdentityIndex % 21f / 21f); Vector2 idealVelocity = -Vector2.UnitY.RotatedBy(MathHelper.Lerp(-0.44f, 0.44f, (float)Math.Sin(Cinders[i].Time / 16f + Cinders[i].IdentityIndex) * 0.5f + 0.5f)); idealVelocity = (idealVelocity + Vector2.UnitX).SafeNormalize(Vector2.UnitY) * flySpeed; float movementInterpolant = MathHelper.Lerp(0.01f, 0.08f, Utils.GetLerpValue(45f, 145f, Cinders[i].Time, true)); Cinders[i].Velocity = Vector2.Lerp(Cinders[i].Velocity, idealVelocity, movementInterpolant); Cinders[i].Time++; Cinders[i].Center += Cinders[i].Velocity; } // Clear away all dead cinders. Cinders.RemoveAll(c => c.Time >= c.Lifetime); // Draw cinders. Texture2D cinderTexture = ModContent.Request("CalamityMod/ExtraTextures/CalamitasCinder").Value; Texture2D cinderTexture2 = ModContent.Request("CalamityMod/ExtraTextures/CalamitasCinder").Value; for (int i = 0; i < Cinders.Count; i++) { Vector2 drawPosition = Cinders[i].Center; spriteBatch.Draw(cinderTexture, drawPosition, null, Cinders[i].DrawColor, 0f, cinderTexture.Size() * 0.5f, Cinders[i].Scale, 0, 0f); } drawColor = Color.White; return true; } } }