LightSources can be assigned to limbs, glowing watcher

This commit is contained in:
Regalis
2016-05-01 18:47:44 +03:00
parent 3114006d86
commit 4cda429ab0
5 changed files with 43 additions and 7 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 210 KiB

After

Width:  |  Height:  |  Size: 242 KiB

View File

@@ -11,6 +11,10 @@
<limb id = "1" radius="50" height="120" flip="true">
<sprite texture="Content/Characters/Watcher/watcher.png" sourcerect="395,0,117,239" depth="0.025" origin="0.5,0.5"/>
<lightsource range="200.0" color="0.8,0.8,1.0,1.0">
<sprite texture="Content/Characters/Watcher/watcher.png" sourcerect="391,282,121,230" depth="0.025" origin="0.5,0.5"/>
</lightsource>
</limb>
<limb id = "2" width="300" height="119" flip="true">

View File

@@ -7,6 +7,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Items.Components;
using System.Collections.Generic;
using Barotrauma.Lights;
namespace Barotrauma
{
@@ -41,6 +42,8 @@ namespace Barotrauma
public FixedMouseJoint pullJoint;
public readonly Lights.LightSource LightSource;
public readonly LimbType type;
public readonly bool ignoreCollisions;
@@ -289,6 +292,10 @@ namespace Barotrauma
}
damagedSprite = new Sprite(subElement, "", damagedSpritePath);
break;
case "lightsource":
LightSource = new LightSource(subElement);
break;
case "attack":
attack = new Attack(subElement);
@@ -397,6 +404,11 @@ namespace Barotrauma
public void Update(float deltaTime)
{
if (LightSource != null)
{
LightSource.Submarine = body.Submarine;
LightSource.Position = Position;
}
if (!character.IsDead) damage = Math.Max(0.0f, damage-deltaTime*0.1f);
@@ -541,7 +553,7 @@ namespace Barotrauma
bodyShapeTexture,
new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
null,
Color.White,
character.Submarine!=null ? Color.White : Color.Cyan,
-body.DrawRotation,
new Vector2(bodyShapeTexture.Width / 2, bodyShapeTexture.Height / 2), 1.0f, SpriteEffects.None, 0.0f);
}
@@ -550,6 +562,7 @@ namespace Barotrauma
public void Remove()
{
sprite.Remove();
if (LightSource != null) LightSource.Remove();
if (damagedSprite != null) damagedSprite.Remove();
body.Remove();
@@ -559,7 +572,6 @@ namespace Barotrauma
bodyShapeTexture.Dispose();
}
if (hitSound != null) hitSound.Remove();
}
}

View File

@@ -152,8 +152,8 @@ namespace Barotrauma.Lights
foreach (LightSource light in lights)
{
if (light.hullsInRange.Count > 0 || light.Color.A < 0.01f || light.Range < 1.0f) continue;
if (!MathUtils.CircleIntersectsRectangle(light.WorldPosition, light.Range, viewRect)) continue;
if (light.hullsInRange.Count > 0 || light.Color.A < 0.01f) continue;
//if (!MathUtils.CircleIntersectsRectangle(light.WorldPosition, light.Range, viewRect)) continue;
light.Draw(spriteBatch);
}

View File

@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Barotrauma.Lights
{
@@ -82,6 +83,21 @@ namespace Barotrauma.Lights
}
}
public LightSource (XElement element)
:this(Vector2.Zero, 100.0f, Color.White, null)
{
float range = ToolBox.GetAttributeFloat(element, "range", 100.0f);
Color color = new Color(ToolBox.GetAttributeVector4(element, "color", Vector4.One));
foreach (XElement subElement in element.Elements())
{
if (subElement.Name.ToString().ToLowerInvariant() != "sprite") continue;
LightSprite = new Sprite(subElement);
LightSprite.Origin = LightSprite.size / 2.0f;
}
}
public LightSource(Vector2 position, float range, Color color, Submarine submarine)
{
hullsInRange = new List<ConvexHull>();
@@ -110,9 +126,13 @@ namespace Barotrauma.Lights
public void Draw(SpriteBatch spriteBatch)
{
Vector2 center = new Vector2(LightTexture.Width / 2, LightTexture.Height / 2);
float scale = range / (lightTexture.Width / 2.0f);
spriteBatch.Draw(lightTexture, new Vector2(WorldPosition.X, -WorldPosition.Y), null, color, 0, center, scale, SpriteEffects.None, 1);
if (range > 1.0f)
{
Vector2 center = new Vector2(LightTexture.Width / 2, LightTexture.Height / 2);
float scale = range / (lightTexture.Width / 2.0f);
spriteBatch.Draw(lightTexture, new Vector2(WorldPosition.X, -WorldPosition.Y), null, color, 0, center, scale, SpriteEffects.None, 1);
}
if (LightSprite != null)
{