diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index a6d01c714..b62cb5ab1 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -350,6 +350,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Content/BackgroundSprites/BackgroundSpritePrefabs.xml b/Subsurface/Content/BackgroundSprites/BackgroundSpritePrefabs.xml index be3735b03..1a9340e21 100644 --- a/Subsurface/Content/BackgroundSprites/BackgroundSpritePrefabs.xml +++ b/Subsurface/Content/BackgroundSprites/BackgroundSpritePrefabs.xml @@ -12,7 +12,7 @@ - + @@ -20,15 +20,32 @@ - + + + + + - + - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Subsurface/Content/BackgroundSprites/vegetation.png b/Subsurface/Content/BackgroundSprites/vegetation.png index 9c4c1937b..6c5f4d0a4 100644 Binary files a/Subsurface/Content/BackgroundSprites/vegetation.png and b/Subsurface/Content/BackgroundSprites/vegetation.png differ diff --git a/Subsurface/Content/BackgroundSprites/vegetation2.png b/Subsurface/Content/BackgroundSprites/vegetation2.png index c0383a41d..2216ad886 100644 Binary files a/Subsurface/Content/BackgroundSprites/vegetation2.png and b/Subsurface/Content/BackgroundSprites/vegetation2.png differ diff --git a/Subsurface/Content/BackgroundSprites/vegetation3.png b/Subsurface/Content/BackgroundSprites/vegetation3.png new file mode 100644 index 000000000..921c0939f Binary files /dev/null and b/Subsurface/Content/BackgroundSprites/vegetation3.png differ diff --git a/Subsurface/Content/BackgroundSprites/vegetation4.png b/Subsurface/Content/BackgroundSprites/vegetation4.png new file mode 100644 index 000000000..41f31ac3a Binary files /dev/null and b/Subsurface/Content/BackgroundSprites/vegetation4.png differ diff --git a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs index 67521f327..9a14fd5b6 100644 --- a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs +++ b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpriteManager.cs @@ -35,10 +35,11 @@ namespace Barotrauma const int GridSize = 1000; private List prefabs = new List(); - - + private List[,] sprites; + private float swingTimer; + public BackgroundSpriteManager(string configPath) { LoadConfig(configPath); @@ -128,7 +129,7 @@ namespace Barotrauma List edges = new List(); foreach (GraphEdge edge in cell.edges) { - if (!edge.isSolid) continue; + if (!edge.isSolid || edge.OutsideLevel) continue; if (prefab.Alignment.HasFlag(Alignment.Bottom)) { @@ -163,31 +164,27 @@ namespace Barotrauma Vector2 pos = closestEdge.Center; pos = closestEdge.point2 + dir * Rand.Range(prefab.Sprite.size.X / 2.0f, length - prefab.Sprite.size.X / 2.0f, false); - - if (prefab.Alignment.HasFlag(Alignment.Top)) - { - pos.Y -= Math.Abs(dir.Y) * prefab.Sprite.size.X / Math.Abs(dir.X); - } - else if (prefab.Alignment.HasFlag(Alignment.Bottom)) - { - pos.Y += Math.Abs(dir.Y) * prefab.Sprite.size.X / Math.Abs(dir.X); - } - + return pos; } + public void Update(float deltaTime) + { + swingTimer += deltaTime; + } + public void DrawSprites(SpriteBatch spriteBatch, Camera cam) { Rectangle indices = Rectangle.Empty; - indices.X = (int)Math.Floor(cam.WorldView.X / (float)GridSize) - 1; + indices.X = (int)Math.Floor(cam.WorldView.X / (float)GridSize) - 2; if (indices.X >= sprites.GetLength(0)) return; - indices.Y = (int)Math.Floor((cam.WorldView.Y - cam.WorldView.Height) / (float)GridSize) - 1; + indices.Y = (int)Math.Floor((cam.WorldView.Y - cam.WorldView.Height) / (float)GridSize) - 2; if (indices.Y >= sprites.GetLength(1)) return; - indices.Width = (int)Math.Ceiling(cam.WorldView.Right / (float)GridSize) + 1; + indices.Width = (int)Math.Ceiling(cam.WorldView.Right / (float)GridSize) + 2; if (indices.Width < 0) return; - indices.Height = (int)Math.Ceiling(cam.WorldView.Y / (float)GridSize) + 1; + indices.Height = (int)Math.Ceiling(cam.WorldView.Y / (float)GridSize) + 2; if (indices.Height < 0) return; indices.X = Math.Max(indices.X, 0); @@ -195,6 +192,8 @@ namespace Barotrauma indices.Width = Math.Min(indices.Width, sprites.GetLength(0)); indices.Height = Math.Min(indices.Height, sprites.GetLength(1)); + float swingState = (float)Math.Sin(swingTimer * 0.1f); + float z = 0.0f; for (int x = indices.X; x < indices.Width; x++) { @@ -202,7 +201,17 @@ namespace Barotrauma { foreach (BackgroundSprite sprite in sprites[x, y]) { - sprite.Prefab.Sprite.Draw(spriteBatch, new Vector2(sprite.Position.X, -sprite.Position.Y), Color.White, sprite.Rotation, sprite.Scale, SpriteEffects.None, z); + sprite.Prefab.Sprite.Draw( + spriteBatch, + new Vector2(sprite.Position.X, -sprite.Position.Y), + Color.White, + sprite.Rotation + swingState*sprite.Prefab.SwingAmount, + sprite.Scale, + SpriteEffects.None, + z); + + GUI.DrawRectangle(spriteBatch, new Vector2(sprite.Position.X, -sprite.Position.Y), new Vector2(10.0f, 10.0f), Color.Red, true); + z += 0.0001f; } } diff --git a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs index c6c3b7ffd..84d924468 100644 --- a/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs +++ b/Subsurface/Source/Characters/BackgroundSprite/BackgroundSpritePrefab.cs @@ -16,6 +16,8 @@ namespace Barotrauma public readonly Vector2 RandomRotation; + public readonly float SwingAmount; + public readonly int Commonness; public BackgroundSpritePrefab(XElement element) @@ -35,6 +37,8 @@ namespace Barotrauma RandomRotation.X = MathHelper.ToRadians(RandomRotation.X); RandomRotation.Y = MathHelper.ToRadians(RandomRotation.Y); + SwingAmount = MathHelper.ToRadians(ToolBox.GetAttributeFloat(element, "swingamount", 0.0f)); + foreach (XElement subElement in element.Elements()) { if (subElement.Name.ToString().ToLowerInvariant() != "sprite") continue; diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index 13766cf55..fffc15a93 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -319,9 +319,17 @@ namespace Barotrauma pathCells.AddRange(CreateBottomHoles(generationParams.BottomHoleProbability, new Rectangle( (int)(borders.Width * 0.2f), 0, (int)(borders.Width * 0.6f), (int)(borders.Height * 0.8f)))); + + foreach (VoronoiCell cell in cells) + { + if (cell.Center.Y < borders.Height / 2) continue; + cell.edges.ForEach(e => e.OutsideLevel = true); + } foreach (VoronoiCell cell in pathCells) { + cell.edges.ForEach(e => e.OutsideLevel = false); + cell.CellType = CellType.Path; cells.Remove(cell); } @@ -653,7 +661,10 @@ namespace Barotrauma foreach (GraphEdge edge in cell.edges) { VoronoiCell adjacent = edge.AdjacentCell(cell); - if (adjacent!=null && !newCells.Contains(adjacent)) newCells.Add(adjacent); + if (adjacent != null && !newCells.Contains(adjacent)) + { + newCells.Add(adjacent); + } } } diff --git a/Subsurface/Source/Map/Levels/LevelRenderer.cs b/Subsurface/Source/Map/Levels/LevelRenderer.cs index c2f64a0b3..2eb4e5c96 100644 --- a/Subsurface/Source/Map/Levels/LevelRenderer.cs +++ b/Subsurface/Source/Map/Levels/LevelRenderer.cs @@ -68,7 +68,9 @@ namespace Barotrauma public void Update(float deltaTime) { - dustOffset -= Vector2.UnitY * 10.0f * (float)deltaTime; + dustOffset -= Vector2.UnitY * 10.0f * deltaTime; + + backgroundSpriteManager.Update(deltaTime); } public void SetWallVertices(VertexPositionTexture[] vertices) @@ -196,7 +198,6 @@ namespace Barotrauma public void RenderWalls(GraphicsDevice graphicsDevice, Camera cam) { - if (wallVertices == null) return; basicEffect.World = cam.ShaderTransform diff --git a/Subsurface/Source/Map/Levels/VoronoiElements.cs b/Subsurface/Source/Map/Levels/VoronoiElements.cs index 57d0baff2..1f5aaff73 100644 --- a/Subsurface/Source/Map/Levels/VoronoiElements.cs +++ b/Subsurface/Source/Map/Levels/VoronoiElements.cs @@ -201,6 +201,8 @@ namespace Voronoi2 public bool isSolid; + public bool OutsideLevel; + public Vector2 Center { get { return (point1 + point2) / 2.0f; }