Walls have an additional background sprite below the destructible sprite, separate parameters for rgb and alpha lerping in the damage shader

This commit is contained in:
Regalis
2016-09-19 21:51:37 +03:00
parent b24359464b
commit f8368f464a
11 changed files with 348 additions and 215 deletions

View File

@@ -86,6 +86,30 @@ namespace Barotrauma
{
get { return null; }
}
public virtual bool DrawBelowWater
{
get
{
return Sprite != null && Sprite.Depth > 0.5f;
}
}
public virtual bool DrawOverWater
{
get
{
return !DrawBelowWater;
}
}
public virtual bool DrawDamageEffect
{
get
{
return false;
}
}
public virtual bool IsLinkable
{
@@ -203,6 +227,8 @@ namespace Barotrauma
public virtual void Draw(SpriteBatch spriteBatch, bool editing, bool back=true) {}
public virtual void DrawDamage(SpriteBatch spriteBatch, Effect damageEffect) {}
public override void Remove()
{
base.Remove();

View File

@@ -43,7 +43,7 @@ namespace Barotrauma
class Structure : MapEntity, IDamageable
{
public static int wallSectionSize = 100;
public static int wallSectionSize = 96;
public static List<Structure> WallList = new List<Structure>();
List<ConvexHull> convexHulls;
@@ -105,6 +105,30 @@ namespace Barotrauma
get { return prefab.MaxHealth; }
}
public override bool DrawBelowWater
{
get
{
return base.DrawBelowWater || prefab.BackgroundSprite != null;
}
}
public override bool DrawOverWater
{
get
{
return !DrawDamageEffect;
}
}
public override bool DrawDamageEffect
{
get
{
return prefab.HasBody;
}
}
public override Rectangle Rect
{
get
@@ -371,12 +395,19 @@ namespace Barotrauma
public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true)
{
if (prefab.sprite == null) return;
Draw(spriteBatch, editing, back, null);
}
public override void DrawDamage(SpriteBatch spriteBatch, Effect damageEffect)
{
Draw(spriteBatch, false, false, damageEffect);
}
private static float prevCutoff;
public void Draw(SpriteBatch spriteBatch, bool editing, bool back = true, Effect damageEffect = null)
private void Draw(SpriteBatch spriteBatch, bool editing, bool back = true, Effect damageEffect = null)
{
if (prefab.sprite == null) return;
@@ -389,69 +420,48 @@ namespace Barotrauma
}
Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition;
if (sections.Length == 1)
{
prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), Vector2.Zero, color, Point.Zero);
return;
}
foreach (WallSection s in sections)
if (back && damageEffect == null)
{
if (damageEffect != null)
if (prefab.BackgroundSprite != null)
{
float newCutoff = Math.Min((s.damage / prefab.MaxHealth)*0.5f - 0.2f, 0.1f);
if (Math.Abs(newCutoff - prevCutoff) > 0.01f)
prefab.BackgroundSprite.DrawTiled(
spriteBatch,
new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)),
new Vector2(rect.Width, rect.Height),
Vector2.Zero, color, Point.Zero);
}
}
if (back == prefab.sprite.Depth > 0.5f || editing)
{
foreach (WallSection s in sections)
{
if (damageEffect != null)
{
damageEffect.Parameters["cutoff"].SetValue(newCutoff);
float newCutoff = Math.Min((s.damage / prefab.MaxHealth), 0.65f);
damageEffect.CurrentTechnique.Passes[0].Apply();
if (Math.Abs(newCutoff - prevCutoff) > 0.01f)
{
damageEffect.Parameters["aCutoff"].SetValue(newCutoff);
damageEffect.Parameters["cCutoff"].SetValue(newCutoff*1.2f);
prevCutoff = newCutoff;
damageEffect.CurrentTechnique.Passes[0].Apply();
prevCutoff = newCutoff;
}
}
}
Point offset = new Point(Math.Abs(rect.Location.X - s.rect.Location.X), Math.Abs(rect.Location.Y - s.rect.Location.Y));
if (sections.Length != 1)
Point offset = new Point(Math.Abs(rect.Location.X - s.rect.Location.X), Math.Abs(rect.Location.Y - s.rect.Location.Y));
prefab.sprite.DrawTiled(spriteBatch, new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height), Vector2.Zero, color, offset);
if (s.isHighLighted)
{
GUI.DrawRectangle(spriteBatch,
new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height),
new Color((s.damage / prefab.MaxHealth), 1.0f - (s.damage / prefab.MaxHealth), 0.0f, 1.0f), true);
s.isHighLighted = false;
}
s.isHighLighted = false;
//if (s.damage < 0.01f) continue;
//GUI.DrawRectangle(spriteBatch,
// new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height),
// Color.Black * (s.damage / prefab.MaxHealth), true);
}
/*
if(_convexHulls == null) return;
var rand = new Random(32434324);
foreach (var hull in _convexHulls)
{
if (sections.Count(x => x.hull == hull) <= 1)
continue;
var col = new Color((int) (255 * rand.NextDouble()), (int)(255 * rand.NextDouble()), (int)(255 * rand.NextDouble()), 255);
GUI.DrawRectangle(spriteBatch,new Vector2 (hull.BoundingBox.X + drawOffset.X, -(hull.BoundingBox.Y + drawOffset.Y)), new Vector2(hull.BoundingBox.Width, hull.BoundingBox.Height),col,true );
}*/
}
private bool OnWallCollision(Fixture f1, Fixture f2, Contact contact)
{
//Structure structure = f1.Body.UserData as Structure;
//if (f2.Body.UserData as Item != null)
//{
// if (prefab.IsPlatform || prefab.StairDirection != Direction.None) return false;
//}
if (prefab.IsPlatform)
{
Limb limb;

View File

@@ -52,6 +52,12 @@ namespace Barotrauma
{
get { return size; }
}
public Sprite BackgroundSprite
{
get;
private set;
}
public static void LoadAll(List<string> filePaths)
{
@@ -74,22 +80,45 @@ namespace Barotrauma
StructurePrefab sp = new StructurePrefab();
sp.name = element.Name.ToString();
Vector4 sourceVector = ToolBox.GetAttributeVector4(element, "sourcerect", new Vector4(0,0,1,1));
//Vector4 sourceVector = ToolBox.GetAttributeVector4(element, "sourcerect", new Vector4(0,0,1,1));
Rectangle sourceRect = new Rectangle(
(int)sourceVector.X,
(int)sourceVector.Y,
(int)sourceVector.Z,
(int)sourceVector.W);
//Rectangle sourceRect = new Rectangle(
// (int)sourceVector.X,
// (int)sourceVector.Y,
// (int)sourceVector.Z,
// (int)sourceVector.W);
if (element.Attribute("sprite") != null)
{
sp.sprite = new Sprite(element.Attribute("sprite").Value, sourceRect, Vector2.Zero);
//if (element.Attribute("sprite") != null)
//{
// sp.sprite = new Sprite(element.Attribute("sprite").Value, sourceRect, Vector2.Zero);
sp.sprite.Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f);
// sp.sprite.Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f);
if (ToolBox.GetAttributeBool(element, "fliphorizontal", false)) sp.sprite.effects = SpriteEffects.FlipHorizontally;
if (ToolBox.GetAttributeBool(element, "flipvertical", false)) sp.sprite.effects = SpriteEffects.FlipVertically;
//}
foreach (XElement subElement in element.Elements())
{
switch (subElement.Name.ToString())
{
case "sprite":
sp.sprite = new Sprite(subElement);
if (ToolBox.GetAttributeBool(subElement, "fliphorizontal", false))
sp.sprite.effects = SpriteEffects.FlipHorizontally;
if (ToolBox.GetAttributeBool(subElement, "flipvertical", false))
sp.sprite.effects = SpriteEffects.FlipVertically;
break;
case "backgroundsprite":
sp.BackgroundSprite = new Sprite(subElement);
if (ToolBox.GetAttributeBool(subElement, "fliphorizontal", false))
sp.BackgroundSprite.effects = SpriteEffects.FlipHorizontally;
if (ToolBox.GetAttributeBool(subElement, "flipvertical", false))
sp.BackgroundSprite.effects = SpriteEffects.FlipVertically;
break;
}
}
MapEntityCategory category;
@@ -119,8 +148,7 @@ namespace Barotrauma
sp.stairDirection = (Direction)Enum.Parse(typeof(Direction), ToolBox.GetAttributeString(element, "stairdirection", "None"), true);
sp.castShadow = ToolBox.GetAttributeBool(element, "castshadow", false);
sp.hasBody = ToolBox.GetAttributeBool(element, "body", false);
return sp;

View File

@@ -287,8 +287,7 @@ namespace Barotrauma
{
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
{
if (MapEntity.mapEntityList[i] is Structure) continue;
if (MapEntity.mapEntityList[i].Sprite == null || MapEntity.mapEntityList[i].Sprite.Depth < 0.5f)
if (MapEntity.mapEntityList[i].DrawOverWater)
MapEntity.mapEntityList[i].Draw(spriteBatch, editing, false);
}
}
@@ -297,12 +296,11 @@ namespace Barotrauma
{
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
{
var structure = MapEntity.mapEntityList[i] as Structure;
if (structure == null || structure.Sprite.Depth > 0.5f) continue;
structure.Draw(spriteBatch, editing, false, damageEffect);
if (MapEntity.mapEntityList[i].DrawDamageEffect)
MapEntity.mapEntityList[i].DrawDamage(spriteBatch, damageEffect);
}
damageEffect.Parameters["cutoff"].SetValue(0.5f);
damageEffect.Parameters["aCutoff"].SetValue(0.0f);
damageEffect.Parameters["cCutoff"].SetValue(0.0f);
}
@@ -310,7 +308,7 @@ namespace Barotrauma
{
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
{
if (MapEntity.mapEntityList[i].Sprite == null || MapEntity.mapEntityList[i].Sprite.Depth >= 0.5f)
if (MapEntity.mapEntityList[i].DrawBelowWater)
MapEntity.mapEntityList[i].Draw(spriteBatch, editing, true);
}
}