diff --git a/Tiles/SunkenSea/BlackPearlPile.cs b/Tiles/SunkenSea/BlackPearlPile.cs index 5b2ffb59e3..1a9223e6af 100644 --- a/Tiles/SunkenSea/BlackPearlPile.cs +++ b/Tiles/SunkenSea/BlackPearlPile.cs @@ -1,7 +1,9 @@ -using CalamityMod.Sounds; +using System; +using CalamityMod.Sounds; using CalamityMod.Systems; using CalamityMod.Tiles.Abyss; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -16,6 +18,8 @@ namespace CalamityMod.Tiles.SunkenSea Main.tileBlockLight[Type] = true; TileID.Sets.HasSlopeFrames[Type] = true; + Main.tileLighted[Type] = true; + Main.tileBlendAll[Type] = true; CalamityUtils.MergeWithGeneral(Type); @@ -51,5 +55,111 @@ namespace CalamityMod.Tiles.SunkenSea { return TileFramingSystem.BetterGemsparkFraming(i, j, resetFrame); } + + private static float GetFade1(int i, int j) + { + return (MathF.Sin(Main.GlobalTimeWrappedHourly * 0.2f) + 1f) / 2f; + } + + private static float GetFade2(int i, int j) + { + return (MathF.Sin(Main.GlobalTimeWrappedHourly * 0.1f + i * 0.08f - j * 0.05f) + 1f) / 2f; + } + public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + { + //IF this glint effect below runs poorly on lower end PC's we should keep it as a setting for those with good PC's + + Tile tile = Framing.GetTileSafely(i, j); + Vector2 offScreen = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); + Vector2 position = new Vector2(i * 16, j * 16) - Main.screenPosition + offScreen; + + int frameX = tile.TileFrameX + (i % 1); + int frameY = tile.TileFrameY + (j % 1); + + Rectangle sourceRect = new Rectangle(frameX, frameY, 16, 16); + + Texture2D GlintTex = ModContent.Request("CalamityMod/Tiles/SunkenSea/BlackPearlPile_Glint").Value; + + Vector2 glintDir = new Vector2(1f, -1f); + glintDir.Normalize(); + + Vector2 screenPos = position; + + float projection = Vector2.Dot(screenPos, glintDir); + + // this sets the length between the glints diagonally + float screenDiagonalLength = Vector2.Dot(new Vector2(Main.screenWidth, Main.screenHeight), glintDir); + float[] beamCenters = new float[] + { + screenDiagonalLength * 0.05f, // upper glint + screenDiagonalLength * 0.5f, // middle glint + screenDiagonalLength * 1.05f // lower glint + }; + + float stripeWidth = 100f; + + foreach (float bc in beamCenters) + { + float dist = Math.Abs(projection - bc); + float strength = MathHelper.Clamp(1f - dist / stripeWidth, 0f, 1f); + + if (strength > 0f) + { + spriteBatch.Draw(GlintTex, position, sourceRect, (Lighting.GetColor(i, j) * 6) * (strength * 0.4f), 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + } + } + } + public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + { + // figure out if the tile is exposed - taken from the coral tiles + if (Main.tile[i, j] == null || + (Main.tile[i - 1, j].HasTile && Main.tile[i + 1, j].HasTile && Main.tile[i, j - 1].HasTile && Main.tile[i, j + 1].HasTile)) + return; + + // get in-game lighting color at this tile + Color litColor = Lighting.GetColor(i, j); + + // convert to brightness factor (0 = dark, 1 = full bright) + float brightness = (litColor.R + litColor.G + litColor.B) / (3f * 255f); + + // flip it so the glow is strongest in the dark + float darknessFactor = 1f - brightness; + + // diagonal glint math + Vector2 glintDir = new Vector2(1f, -1f); + glintDir.Normalize(); + + Vector2 screenPos = new Vector2(i * 16, j * 16) - Main.screenPosition; + float projection = Vector2.Dot(screenPos, glintDir); + float screenDiagonalLength = Vector2.Dot(new Vector2(Main.screenWidth, Main.screenHeight), glintDir); + + float[] beamCenters = + { + screenDiagonalLength * 0.05f, + screenDiagonalLength * 0.5f, + screenDiagonalLength * 1.05f + }; + + float stripeWidth = 100f; + float maxStrength = 0f; + + foreach (float bc in beamCenters) + { + float dist = Math.Abs(projection - bc); + float strength = MathHelper.Clamp(1f - dist / stripeWidth, 0f, 1f); + if (strength > maxStrength) + maxStrength = strength; + } + + if (maxStrength > 0f) + { + // base intensity scaled by glint strength and darkness + float intensity = 0.6f * maxStrength * (0.5f + darknessFactor * 0.5f); + + r = (67f / 155f) * intensity; + g = (68f / 155f) * intensity; + b = (87f / 155f) * intensity; + } + } } } diff --git a/Tiles/SunkenSea/BlackPearlPile_Glint.png b/Tiles/SunkenSea/BlackPearlPile_Glint.png new file mode 100644 index 0000000000..693c93520c Binary files /dev/null and b/Tiles/SunkenSea/BlackPearlPile_Glint.png differ diff --git a/Tiles/SunkenSea/PinkPearlPile.cs b/Tiles/SunkenSea/PinkPearlPile.cs index 7bcd41ef34..2ef85911ee 100644 --- a/Tiles/SunkenSea/PinkPearlPile.cs +++ b/Tiles/SunkenSea/PinkPearlPile.cs @@ -1,10 +1,14 @@ -using CalamityMod.Sounds; +using System; +using CalamityMod.Sounds; using CalamityMod.Systems; using CalamityMod.Tiles.Abyss; +using Microsoft.CodeAnalysis.Text; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; +using static CalamityMod.Projectiles.Rogue.FinalDawnFlame; namespace CalamityMod.Tiles.SunkenSea { @@ -14,6 +18,7 @@ namespace CalamityMod.Tiles.SunkenSea { Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; + Main.tileLighted[Type] = true; CalamityUtils.MergeWithGeneral(Type); @@ -46,5 +51,113 @@ namespace CalamityMod.Tiles.SunkenSea { return TileFramingSystem.BetterGemsparkFraming(i, j, resetFrame); } + + private static float GetFade1(int i, int j) + { + return (MathF.Sin(Main.GlobalTimeWrappedHourly * 0.2f) + 1f) / 2f; + } + + private static float GetFade2(int i, int j) + { + return (MathF.Sin(Main.GlobalTimeWrappedHourly * 0.1f + i * 0.08f - j * 0.05f) + 1f) / 2f; + } + public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + { + //IF this glint effect below runs poorly on lower end PC's we should keep it as a setting for those with good PC's + + Tile tile = Framing.GetTileSafely(i, j); + Vector2 offScreen = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); + Vector2 position = new Vector2(i * 16, j * 16) - Main.screenPosition + offScreen; + + int frameX = tile.TileFrameX + (i % 1 ); + int frameY = tile.TileFrameY + (j % 1 ); + + Rectangle sourceRect = new Rectangle(frameX, frameY, 16, 16); + + + Texture2D GlintTex = ModContent.Request("CalamityMod/Tiles/SunkenSea/PinkPearlPile_Glint").Value; + + Vector2 glintDir = new Vector2(1f, -1f); + glintDir.Normalize(); + + Vector2 screenPos = position; + + float projection = Vector2.Dot(screenPos, glintDir); + + // this sets the length between the glints diagonally + float screenDiagonalLength = Vector2.Dot(new Vector2(Main.screenWidth, Main.screenHeight), glintDir); + float[] beamCenters = new float[] + { + screenDiagonalLength * 0.05f, // upper glint + screenDiagonalLength * 0.5f, // middle glint + screenDiagonalLength * 1.05f // lower glint + }; + + float stripeWidth = 100f; + + foreach (float bc in beamCenters) + { + float dist = Math.Abs(projection - bc); + float strength = MathHelper.Clamp(1f - dist / stripeWidth, 0f, 1f); + + if (strength > 0f) + { + spriteBatch.Draw(GlintTex, position, sourceRect, (Lighting.GetColor(i, j) * 6 ) * (strength * 0.4f), 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + } + } + } + public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + { + // figure out if the tile is exposed - taken from the coral tiles + if (Main.tile[i, j] == null || + (Main.tile[i - 1, j].HasTile && Main.tile[i + 1, j].HasTile && Main.tile[i, j - 1].HasTile && Main.tile[i, j + 1].HasTile)) + return; + + // get in-game lighting color at this tile + Color litColor = Lighting.GetColor(i, j); + + // convert to brightness factor (0 = dark, 1 = full bright) + float brightness = (litColor.R + litColor.G + litColor.B) / (3f * 255f); + + // flip it so the glow is strongest in the dark + float darknessFactor = 1f - brightness; + + // diagonal glint math + Vector2 glintDir = new Vector2(1f, -1f); + glintDir.Normalize(); + + Vector2 screenPos = new Vector2(i * 16, j * 16) - Main.screenPosition; + float projection = Vector2.Dot(screenPos, glintDir); + float screenDiagonalLength = Vector2.Dot(new Vector2(Main.screenWidth, Main.screenHeight), glintDir); + + float[] beamCenters = + { + screenDiagonalLength * 0.05f, + screenDiagonalLength * 0.5f, + screenDiagonalLength * 1.05f + }; + + float stripeWidth = 100f; + float maxStrength = 0f; + + foreach (float bc in beamCenters) + { + float dist = Math.Abs(projection - bc); + float strength = MathHelper.Clamp(1f - dist / stripeWidth, 0f, 1f); + if (strength > maxStrength) + maxStrength = strength; + } + + if (maxStrength > 0f) + { + // base intensity scaled by glint strength and darkness + float intensity = 0.6f * maxStrength * (0.5f + darknessFactor * 0.5f); + + r = (172f / 255f) * intensity; + g = (112f / 255f) * intensity; + b = (145f / 255f) * intensity; + } + } + } } diff --git a/Tiles/SunkenSea/PinkPearlPile_Glint.png b/Tiles/SunkenSea/PinkPearlPile_Glint.png new file mode 100644 index 0000000000..bd5253d1eb Binary files /dev/null and b/Tiles/SunkenSea/PinkPearlPile_Glint.png differ diff --git a/Tiles/SunkenSea/WhitePearlPile.cs b/Tiles/SunkenSea/WhitePearlPile.cs index 94938f9b10..6d01cbef09 100644 --- a/Tiles/SunkenSea/WhitePearlPile.cs +++ b/Tiles/SunkenSea/WhitePearlPile.cs @@ -1,7 +1,9 @@ -using CalamityMod.Sounds; +using System; +using CalamityMod.Sounds; using CalamityMod.Systems; using CalamityMod.Tiles.Abyss; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -14,6 +16,7 @@ namespace CalamityMod.Tiles.SunkenSea { Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; + Main.tileLighted[Type] = true; CalamityUtils.MergeWithGeneral(Type); @@ -47,5 +50,113 @@ namespace CalamityMod.Tiles.SunkenSea { return TileFramingSystem.BetterGemsparkFraming(i, j, resetFrame); } + + private static float GetFade1(int i, int j) + { + return (MathF.Sin(Main.GlobalTimeWrappedHourly * 0.2f) + 1f) / 2f; + } + + private static float GetFade2(int i, int j) + { + return (MathF.Sin(Main.GlobalTimeWrappedHourly * 0.1f + i * 0.08f - j * 0.05f) + 1f) / 2f; + } + public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + { + //IF this glint effect below runs poorly on lower end PC's we should keep it as a setting for those with good PC's + + Tile tile = Framing.GetTileSafely(i, j); + Vector2 offScreen = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); + Vector2 position = new Vector2(i * 16, j * 16) - Main.screenPosition + offScreen; + + int frameX = tile.TileFrameX + (i % 1); + int frameY = tile.TileFrameY + (j % 1); + + Rectangle sourceRect = new Rectangle(frameX, frameY, 16, 16); + + Texture2D GlintTex = ModContent.Request("CalamityMod/Tiles/SunkenSea/WhitePearlPile_Glint").Value; + + Vector2 glintDir = new Vector2(1f, -1f); + glintDir.Normalize(); + + Vector2 screenPos = position; + + float projection = Vector2.Dot(screenPos, glintDir); + + // this sets the length between the glints diagonally + float screenDiagonalLength = Vector2.Dot(new Vector2(Main.screenWidth, Main.screenHeight), glintDir); + float[] beamCenters = new float[] + { + screenDiagonalLength * 0.05f, // upper glint + screenDiagonalLength * 0.5f, // middle glint + screenDiagonalLength * 1.05f // lower glint + }; + + float stripeWidth = 100f; + + foreach (float bc in beamCenters) + { + float dist = Math.Abs(projection - bc); + float strength = MathHelper.Clamp(1f - dist / stripeWidth, 0f, 1f); + + if (strength > 0f) + { + spriteBatch.Draw(GlintTex, position, sourceRect, (Lighting.GetColor(i, j) * 6) * (strength * 0.4f), 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + } + } + } + public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + { + // figure out if the tile is exposed - taken from the coral tiles + if (Main.tile[i, j] == null || + (Main.tile[i - 1, j].HasTile && Main.tile[i + 1, j].HasTile && Main.tile[i, j - 1].HasTile && Main.tile[i, j + 1].HasTile)) + return; + + // get in-game lighting color at this tile + Color litColor = Lighting.GetColor(i, j); + + // convert to brightness factor (0 = dark, 1 = full bright) + float brightness = (litColor.R + litColor.G + litColor.B) / (3f * 255f); + + // flip it so the glow is strongest in the dark + float darknessFactor = 1f - brightness; + + // diagonal glint math + Vector2 glintDir = new Vector2(1f, -1f); + glintDir.Normalize(); + + Vector2 screenPos = new Vector2(i * 16, j * 16) - Main.screenPosition; + float projection = Vector2.Dot(screenPos, glintDir); + float screenDiagonalLength = Vector2.Dot(new Vector2(Main.screenWidth, Main.screenHeight), glintDir); + + float[] beamCenters = + { + screenDiagonalLength * 0.05f, + screenDiagonalLength * 0.5f, + screenDiagonalLength * 1.05f + }; + + float stripeWidth = 100f; + float maxStrength = 0f; + + foreach (float bc in beamCenters) + { + float dist = Math.Abs(projection - bc); + float strength = MathHelper.Clamp(1f - dist / stripeWidth, 0f, 1f); + if (strength > maxStrength) + maxStrength = strength; + } + + if (maxStrength > 0f) + { + // base intensity scaled by glint strength and darkness (min = 0.0f, max = 1.0f) + float intensity = 0.6f * maxStrength * (0.5f + darknessFactor * 0.5f); + //float intensity = ((float)(Math.Pow(10.0, (brightness * 2 - 2))) - 0.01f) / 0.99f; was trying to do something cool, may come back to it later + + + r = (185f / 255f) * intensity; + g = (164f / 255f) * intensity; + b = (184f / 255f) * intensity; + } + } } } diff --git a/Tiles/SunkenSea/WhitePearlPile_Glint.png b/Tiles/SunkenSea/WhitePearlPile_Glint.png new file mode 100644 index 0000000000..3a8280eeb8 Binary files /dev/null and b/Tiles/SunkenSea/WhitePearlPile_Glint.png differ diff --git a/World/SunkenSea.cs b/World/SunkenSea.cs index 769ca64ca5..317f14dd43 100644 --- a/World/SunkenSea.cs +++ b/World/SunkenSea.cs @@ -1572,13 +1572,7 @@ namespace CalamityMod.World { int RandStyle() => WorldGen.genRand.Next(8); int style = RandStyle(); - if (WorldGen.genRand.NextBool(50) && !Main.tile[X - 1, Y].HasTile) - WorldUtils.Gen(new Point(X, Y), new Shapes.Circle(3), Actions.Chain(new GenAction[] - { - new Modifiers.OnlyTiles((ushort)ModContent.TileType(),(ushort)ModContent.TileType()), - new Actions.ClearTile(), - new Actions.PlaceTile((ushort)ModContent.TileType()), - })); + //BranchCoralsOnSand if (WorldGen.genRand.NextBool(25)) { @@ -1650,13 +1644,6 @@ namespace CalamityMod.World //radiant reefs ambient tiles if (Main.tile[X, Y].TileType == ModContent.TileType()) { - if (WorldGen.genRand.NextBool(100) && !Main.tile[X - 1, Y].HasTile) - WorldUtils.Gen(new Point(X, Y), new Shapes.Circle(7), Actions.Chain(new GenAction[] - { - new Modifiers.OnlyTiles((ushort)ModContent.TileType()), - new Actions.ClearTile(), - new Actions.PlaceTile((ushort)ModContent.TileType()), - })); //Driftwood Ambiance if (WorldGen.genRand.NextBool(15)) { @@ -1753,26 +1740,35 @@ namespace CalamityMod.World } } // Pearl Autism - if (Main.tile[X, Y].TileType == ModContent.TileType()) + if (Main.tile[X, Y].TileType == ModContent.TileType()) { - if (WorldGen.genRand.NextBool(50) && !Main.tile[X - 1, Y].HasTile) - WorldUtils.Gen(new Point(X, Y), new Shapes.Circle(3), Actions.Chain(new GenAction[] + if (WorldGen.genRand.NextBool(60) && !Main.tile[X - 1, Y].HasTile) + WorldUtils.Gen(new Point(X, Y), new Shapes.Circle(2), Actions.Chain(new GenAction[] { - new Modifiers.OnlyTiles((ushort)ModContent.TileType()), + new Modifiers.OnlyTiles((ushort)ModContent.TileType()), new Actions.ClearTile(), new Actions.PlaceTile((ushort)ModContent.TileType()), })); } if (Main.tile[X, Y].TileType == ModContent.TileType()) { - if (WorldGen.genRand.NextBool(30) && !Main.tile[X - 1, Y].HasTile) - WorldUtils.Gen(new Point(X, Y), new Shapes.Circle(3), Actions.Chain(new GenAction[] + if (WorldGen.genRand.NextBool(60) && !Main.tile[X - 1, Y].HasTile) + WorldUtils.Gen(new Point(X, Y), new Shapes.Circle(2), Actions.Chain(new GenAction[] { new Modifiers.OnlyTiles((ushort)ModContent.TileType()), new Actions.ClearTile(), new Actions.PlaceTile((ushort)ModContent.TileType()), })); } + + if (Main.tile[X, Y].TileType == ModContent.TileType()) + if (WorldGen.genRand.NextBool(60) && !Main.tile[X - 1, Y].HasTile) + WorldUtils.Gen(new Point(X, Y), new Shapes.Circle(2), Actions.Chain(new GenAction[] + { + new Modifiers.OnlyTiles((ushort)ModContent.TileType()), + new Actions.ClearTile(), + new Actions.PlaceTile((ushort)ModContent.TileType()), + })); } } }