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

@@ -11,6 +11,10 @@
<limb id = "1" radius="50" height="120" flip="true"> <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"/> <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>
<limb id = "2" width="300" height="119" flip="true"> <limb id = "2" width="300" height="119" flip="true">
+14 -2
View File
@@ -7,6 +7,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Items.Components; using Barotrauma.Items.Components;
using System.Collections.Generic; using System.Collections.Generic;
using Barotrauma.Lights;
namespace Barotrauma namespace Barotrauma
{ {
@@ -41,6 +42,8 @@ namespace Barotrauma
public FixedMouseJoint pullJoint; public FixedMouseJoint pullJoint;
public readonly Lights.LightSource LightSource;
public readonly LimbType type; public readonly LimbType type;
public readonly bool ignoreCollisions; public readonly bool ignoreCollisions;
@@ -289,6 +292,10 @@ namespace Barotrauma
} }
damagedSprite = new Sprite(subElement, "", damagedSpritePath); damagedSprite = new Sprite(subElement, "", damagedSpritePath);
break;
case "lightsource":
LightSource = new LightSource(subElement);
break; break;
case "attack": case "attack":
attack = new Attack(subElement); attack = new Attack(subElement);
@@ -397,6 +404,11 @@ namespace Barotrauma
public void Update(float deltaTime) 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); if (!character.IsDead) damage = Math.Max(0.0f, damage-deltaTime*0.1f);
@@ -541,7 +553,7 @@ namespace Barotrauma
bodyShapeTexture, bodyShapeTexture,
new Vector2(body.DrawPosition.X, -body.DrawPosition.Y), new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
null, null,
Color.White, character.Submarine!=null ? Color.White : Color.Cyan,
-body.DrawRotation, -body.DrawRotation,
new Vector2(bodyShapeTexture.Width / 2, bodyShapeTexture.Height / 2), 1.0f, SpriteEffects.None, 0.0f); new Vector2(bodyShapeTexture.Width / 2, bodyShapeTexture.Height / 2), 1.0f, SpriteEffects.None, 0.0f);
} }
@@ -550,6 +562,7 @@ namespace Barotrauma
public void Remove() public void Remove()
{ {
sprite.Remove(); sprite.Remove();
if (LightSource != null) LightSource.Remove();
if (damagedSprite != null) damagedSprite.Remove(); if (damagedSprite != null) damagedSprite.Remove();
body.Remove(); body.Remove();
@@ -559,7 +572,6 @@ namespace Barotrauma
bodyShapeTexture.Dispose(); bodyShapeTexture.Dispose();
} }
if (hitSound != null) hitSound.Remove(); if (hitSound != null) hitSound.Remove();
} }
} }
+2 -2
View File
@@ -152,8 +152,8 @@ namespace Barotrauma.Lights
foreach (LightSource light in lights) foreach (LightSource light in lights)
{ {
if (light.hullsInRange.Count > 0 || light.Color.A < 0.01f || light.Range < 1.0f) continue; if (light.hullsInRange.Count > 0 || light.Color.A < 0.01f) continue;
if (!MathUtils.CircleIntersectsRectangle(light.WorldPosition, light.Range, viewRect)) continue; //if (!MathUtils.CircleIntersectsRectangle(light.WorldPosition, light.Range, viewRect)) continue;
light.Draw(spriteBatch); light.Draw(spriteBatch);
} }
+23 -3
View File
@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Xml.Linq;
namespace Barotrauma.Lights 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) public LightSource(Vector2 position, float range, Color color, Submarine submarine)
{ {
hullsInRange = new List<ConvexHull>(); hullsInRange = new List<ConvexHull>();
@@ -110,9 +126,13 @@ namespace Barotrauma.Lights
public void Draw(SpriteBatch spriteBatch) public void Draw(SpriteBatch spriteBatch)
{ {
Vector2 center = new Vector2(LightTexture.Width / 2, LightTexture.Height / 2); if (range > 1.0f)
float scale = range / (lightTexture.Width / 2.0f); {
spriteBatch.Draw(lightTexture, new Vector2(WorldPosition.X, -WorldPosition.Y), null, color, 0, center, scale, SpriteEffects.None, 1); 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) if (LightSprite != null)
{ {