More background sprites (+ some sprites swing slightly, sprites are less likely to be placed in unreachable places)

This commit is contained in:
Regalis
2016-09-13 21:23:37 +03:00
parent fa15428ed2
commit eae854abbc
11 changed files with 75 additions and 25 deletions

View File

@@ -350,6 +350,12 @@
<Content Include="Content\BackgroundSprites\vegetation2.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\BackgroundSprites\vegetation3.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\BackgroundSprites\vegetation4.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Charybdis\charybdis.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@@ -12,7 +12,7 @@
<Sprite texture="Content/BackgroundSprites/vegetation.png" sourcerect="0,667,275,357" origin="0.5,1.0"/>
</kelp1>
<stalk alignment="Top" minsize="0.5" maxsize="1.5" commonness="1" randomrotation="-10,10">
<stalk alignment="Top" minsize="0.5" maxsize="1.5" commonness="1" swingamount="2" randomrotation="-10,10">
<Sprite texture="Content/BackgroundSprites/vegetation.png" sourcerect="775,0,249,849" origin="0.5,0.95"/>
</stalk>
@@ -20,15 +20,32 @@
<Sprite texture="Content/BackgroundSprites/vegetation.png" sourcerect="544,0,228,561" origin="0.5,0.95"/>
</spike>
<branches1 minsize="0.5" maxsize="2.0" alignwithsurface="true" randomrotation="-20,20" commonness="4">
<leaves minsize="0.5" maxsize="1.5" alignwithsurface="true" commonness="3">
<Sprite texture="Content/BackgroundSprites/vegetation.png" sourcerect="305,722,461,301" origin="0.6,0.8"/>
</leaves>
<branches1 minsize="0.5" maxsize="2.0" alignwithsurface="true" swingamount="3" randomrotation="-20,20" commonness="4">
<Sprite texture="Content/BackgroundSprites/vegetation2.png" sourcerect="0,0,525,484" origin="0.5,0.9"/>
</branches1>
<branches2 minsize="0.5" maxsize="2.0" alignwithsurface="true" randomrotation="-20,20" commonness="4">
<branches2 minsize="0.5" maxsize="2.0" alignwithsurface="true" swingamount="3" randomrotation="-20,20" commonness="4">
<Sprite texture="Content/BackgroundSprites/vegetation2.png" sourcerect="255,0,246,479" origin="0.5,0.9"/>
</branches2>
<fungus minsize="0.5" maxsize="1.5" alignwithsurface="true" commonness="3">
<fungus minsize="0.5" maxsize="1.5" alignwithsurface="true" swingamount="1" commonness="3">
<Sprite texture="Content/BackgroundSprites/vegetation2.png" sourcerect="0,681,442,343" origin="0.5,0.9"/>
</fungus>
<thistle alignment="Top" minsize="0.5" maxsize="1.5" randomrotation="-10,10" swingamount="5" commonness="3">
<Sprite texture="Content/BackgroundSprites/vegetation2.png" sourcerect="449,500,252,524" origin="0.5,0.95"/>
</thistle>
<branch alignment="Top" minsize="1" maxsize="3" randomrotation="-30,30" swingamount="10" commonness="10">
<Sprite texture="Content/BackgroundSprites/vegetation3.png" origin="0.5,0.95"/>
</branch>
<branch alignment="Top" minsize="1" maxsize="3" randomrotation="-30,30" swingamount="8" commonness="10">
<Sprite texture="Content/BackgroundSprites/vegetation4.png" origin="0.5,0.95"/>
</branch>
</backgroundsprites>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 984 KiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 832 KiB

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 832 KiB

View File

@@ -35,10 +35,11 @@ namespace Barotrauma
const int GridSize = 1000;
private List<BackgroundSpritePrefab> prefabs = new List<BackgroundSpritePrefab>();
private List<BackgroundSprite>[,] sprites;
private float swingTimer;
public BackgroundSpriteManager(string configPath)
{
LoadConfig(configPath);
@@ -128,7 +129,7 @@ namespace Barotrauma
List<GraphEdge> edges = new List<GraphEdge>();
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;
}
}

View File

@@ -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;

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -201,6 +201,8 @@ namespace Voronoi2
public bool isSolid;
public bool OutsideLevel;
public Vector2 Center
{
get { return (point1 + point2) / 2.0f; }