More background sprites again, sprite commonness can vary between different level types
This commit is contained in:
@@ -356,6 +356,9 @@
|
||||
<Content Include="Content\BackgroundSprites\vegetation4.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\BackgroundSprites\vegetation5.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Characters\Charybdis\charybdis.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
||||
@@ -9,14 +9,18 @@
|
||||
</hanging2>
|
||||
|
||||
<kelp1 alignment="Top" minsize="0.5" maxsize="1.5" commonness="10">
|
||||
<overridecommonness commonness="0" leveltype="Open" />
|
||||
<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" swingamount="2" randomrotation="-10,10">
|
||||
<overridecommonness commonness="0" leveltype="Open" />
|
||||
<overridecommonness commonness="5" leveltype="Maze" />
|
||||
<Sprite texture="Content/BackgroundSprites/vegetation.png" sourcerect="775,0,249,849" origin="0.5,0.95"/>
|
||||
</stalk>
|
||||
|
||||
<spike alignment="Top" minsize="0.5" maxsize="1.5" alignwithsurface="true" randomrotation="-20,20" commonness="2">
|
||||
<overridecommonness commonness="0" leveltype="Open" />
|
||||
<Sprite texture="Content/BackgroundSprites/vegetation.png" sourcerect="544,0,228,561" origin="0.5,0.95"/>
|
||||
</spike>
|
||||
|
||||
@@ -25,27 +29,53 @@
|
||||
</leaves>
|
||||
|
||||
<branches1 minsize="0.5" maxsize="2.0" alignwithsurface="true" swingamount="3" randomrotation="-20,20" commonness="4">
|
||||
<overridecommonness commonness="10" leveltype="Maze" />
|
||||
<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" swingamount="3" randomrotation="-20,20" commonness="4">
|
||||
<overridecommonness commonness="10" leveltype="Maze" />
|
||||
<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" swingamount="1" commonness="3">
|
||||
<overridecommonness commonness="10" leveltype="Maze" />
|
||||
<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">
|
||||
<overridecommonness commonness="0" leveltype="Open" />
|
||||
<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">
|
||||
<overridecommonness commonness="0" leveltype="Open" />
|
||||
<overridecommonness commonness="1" leveltype="Pillars" />
|
||||
<overridecommonness commonness="1" leveltype="Slabs" />
|
||||
<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"/>
|
||||
<overridecommonness commonness="0" leveltype="Open" />
|
||||
<overridecommonness commonness="1" leveltype="Pillars" />
|
||||
<overridecommonness commonness="1" leveltype="Slabs" />
|
||||
<Sprite texture="Content/BackgroundSprites/vegetation4.png" sourcerect="0,0,818,1024" origin="0.5,0.95"/>
|
||||
</branch>
|
||||
|
||||
|
||||
<hay alignment="Top" minsize="0.5" maxsize="1.5" randomrotation="-10,10" swingamount="5" commonness="3">
|
||||
<overridecommonness commonness="0" leveltype="Open" />
|
||||
<Sprite texture="Content/BackgroundSprites/vegetation4.png" sourcerect="820,245,204,779" origin="0.5,0.95"/>
|
||||
</hay>
|
||||
|
||||
<branch minsize="1" maxsize="3" alignwithsurface="true" randomrotation="-30,30" swingamount="10" commonness="0">
|
||||
<overridecommonness commonness="10" leveltype="Pillars" />
|
||||
<overridecommonness commonness="10" leveltype="Slabs" />
|
||||
<Sprite texture="Content/BackgroundSprites/vegetation5.png" sourcerect="0,0,555,1024" origin="0.6,0.95"/>
|
||||
</branch>
|
||||
|
||||
<branch minsize="1" maxsize="3" alignwithsurface="true" randomrotation="-30,30" swingamount="10" commonness="0">
|
||||
<overridecommonness commonness="10" leveltype="Pillars" />
|
||||
<overridecommonness commonness="10" leveltype="Slabs" />
|
||||
<Sprite texture="Content/BackgroundSprites/vegetation5.png" sourcerect="580,151,444,873" origin="0.3,0.95"/>
|
||||
</branch>
|
||||
</backgroundsprites>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 832 KiB After Width: | Height: | Size: 1.0 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 903 KiB |
@@ -84,7 +84,7 @@ namespace Barotrauma
|
||||
|
||||
for (int i = 0 ; i < amount; i++)
|
||||
{
|
||||
BackgroundSpritePrefab prefab = GetRandomPrefab();
|
||||
BackgroundSpritePrefab prefab = GetRandomPrefab(level.GenerationParams.Name);
|
||||
GraphEdge selectedEdge = null;
|
||||
Vector2? pos = FindSpritePosition(level, prefab, out selectedEdge);
|
||||
|
||||
@@ -131,14 +131,14 @@ namespace Barotrauma
|
||||
{
|
||||
if (!edge.isSolid || edge.OutsideLevel) continue;
|
||||
|
||||
if (prefab.Alignment.HasFlag(Alignment.Bottom))
|
||||
if (prefab.Alignment.HasFlag(Alignment.Bottom) &&
|
||||
Math.Abs(edge.point1.X - edge.point2.X) < Math.Abs(edge.point1.Y - edge.point2.Y))
|
||||
{
|
||||
if (Math.Abs(edge.point1.X - edge.point2.X) < Math.Abs(edge.point1.Y - edge.point2.Y)) continue;
|
||||
if (edge.Center.Y < cell.Center.Y) edges.Add(edge);
|
||||
}
|
||||
else if (prefab.Alignment.HasFlag(Alignment.Top))
|
||||
else if (prefab.Alignment.HasFlag(Alignment.Top) &&
|
||||
Math.Abs(edge.point1.X - edge.point2.X) < Math.Abs(edge.point1.Y - edge.point2.Y))
|
||||
{
|
||||
if (Math.Abs(edge.point1.X - edge.point2.X) < Math.Abs(edge.point1.Y - edge.point2.Y)) continue;
|
||||
if (edge.Center.Y > cell.Center.Y) edges.Add(edge);
|
||||
}
|
||||
else if (prefab.Alignment.HasFlag(Alignment.Left))
|
||||
@@ -210,7 +210,10 @@ namespace Barotrauma
|
||||
SpriteEffects.None,
|
||||
z);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Vector2(sprite.Position.X, -sprite.Position.Y), new Vector2(10.0f, 10.0f), Color.Red, true);
|
||||
if (GameMain.DebugDraw)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, new Vector2(sprite.Position.X, -sprite.Position.Y), new Vector2(10.0f, 10.0f), Color.Red, true);
|
||||
}
|
||||
|
||||
z += 0.0001f;
|
||||
}
|
||||
@@ -218,24 +221,24 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private BackgroundSpritePrefab GetRandomPrefab()
|
||||
private BackgroundSpritePrefab GetRandomPrefab(string levelType)
|
||||
{
|
||||
int totalCommonness = 0;
|
||||
foreach (BackgroundSpritePrefab prefab in prefabs)
|
||||
{
|
||||
totalCommonness += prefab.Commonness;
|
||||
totalCommonness += prefab.GetCommonness(levelType);
|
||||
}
|
||||
|
||||
float randomNumber = Rand.Int(totalCommonness+1, false);
|
||||
|
||||
foreach (BackgroundSpritePrefab prefab in prefabs)
|
||||
{
|
||||
if (randomNumber <= prefab.Commonness)
|
||||
if (randomNumber <= prefab.GetCommonness(levelType))
|
||||
{
|
||||
return prefab;
|
||||
}
|
||||
|
||||
randomNumber -= prefab.Commonness;
|
||||
randomNumber -= prefab.GetCommonness(levelType);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
@@ -20,11 +21,16 @@ namespace Barotrauma
|
||||
|
||||
public readonly int Commonness;
|
||||
|
||||
public Dictionary<string, int> OverrideCommonness;
|
||||
|
||||
public BackgroundSpritePrefab(XElement element)
|
||||
{
|
||||
string alignmentStr = ToolBox.GetAttributeString(element, "alignment", "BottomCenter");
|
||||
string alignmentStr = ToolBox.GetAttributeString(element, "alignment", "");
|
||||
|
||||
if (!Enum.TryParse(alignmentStr, out Alignment)) Alignment = Alignment.BottomCenter;
|
||||
if (string.IsNullOrEmpty(alignmentStr) || !Enum.TryParse(alignmentStr, out Alignment))
|
||||
{
|
||||
Alignment = Alignment.Top | Alignment.Bottom | Alignment.Left | Alignment.Right;
|
||||
}
|
||||
|
||||
Commonness = ToolBox.GetAttributeInt(element, "commonness", 1);
|
||||
|
||||
@@ -39,14 +45,37 @@ namespace Barotrauma
|
||||
|
||||
SwingAmount = MathHelper.ToRadians(ToolBox.GetAttributeFloat(element, "swingamount", 0.0f));
|
||||
|
||||
OverrideCommonness = new Dictionary<string, int>();
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLowerInvariant() != "sprite") continue;
|
||||
switch(subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "sprite":
|
||||
Sprite = new Sprite(subElement);
|
||||
break;
|
||||
case "overridecommonness":
|
||||
string levelType = ToolBox.GetAttributeString(subElement, "leveltype", "");
|
||||
if (!OverrideCommonness.ContainsKey(levelType))
|
||||
{
|
||||
OverrideCommonness.Add(levelType, ToolBox.GetAttributeInt(subElement, "commonness", 1));
|
||||
}
|
||||
break;
|
||||
|
||||
Sprite = new Sprite(subElement);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int GetCommonness(string levelType)
|
||||
{
|
||||
int commonness = 0;
|
||||
if (!OverrideCommonness.TryGetValue(levelType, out commonness))
|
||||
{
|
||||
return Commonness;
|
||||
}
|
||||
|
||||
return commonness;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +119,11 @@ namespace Barotrauma
|
||||
private set;
|
||||
}
|
||||
|
||||
public LevelGenerationParams GenerationParams
|
||||
{
|
||||
get { return generationParams; }
|
||||
}
|
||||
|
||||
public Color BackgroundColor
|
||||
{
|
||||
get { return backgroundColor; }
|
||||
|
||||
Reference in New Issue
Block a user