Obstructing vision when wearing a diving suit or mask
This commit is contained in:
Binary file not shown.
@@ -515,6 +515,9 @@
|
||||
<Content Include="Content\Lights\penumbra.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Lights\visioncircle.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Map\beaconSymbol.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
|
||||
<Wearable limbtype="Head" slots="Any,Head">
|
||||
<sprite texture="DivingMask.png" limb="Head" sourcerect="1,1,37,38"/>
|
||||
<StatusEffect type="OnWearing" target="Character" ObstructVision="true" setvalue="true" disabledeltatime="true"/>
|
||||
|
||||
</Wearable>
|
||||
|
||||
<ItemContainer capacity="1" hideitems="true">
|
||||
@@ -61,7 +63,7 @@
|
||||
<sprite texture="DivingSuit.png" limb="RightLeg" sourcerect="17,47,21,51" origin="0.5,0.55" depth="0.02" hidelimb="true"/>
|
||||
<sprite texture="DivingSuit.png" limb="LeftLeg" sourcerect="17,47,21,51" origin="0.5,0.55" depth="0.02" hidelimb="true"/>
|
||||
|
||||
<StatusEffect type="OnWearing" target="Character" PressureProtection="100.0" SpeedMultiplier="0.7" LowPassMultiplier="0.2" setvalue="true" disabledeltatime="true"/>
|
||||
<StatusEffect type="OnWearing" target="Character" ObstructVision="true" PressureProtection="100.0" SpeedMultiplier="0.6" LowPassMultiplier="0.2" setvalue="true" disabledeltatime="true"/>
|
||||
</Wearable>
|
||||
|
||||
<ItemContainer capacity="1" hideitems="true">
|
||||
|
||||
BIN
Subsurface/Content/Lights/visioncircle.png
Normal file
BIN
Subsurface/Content/Lights/visioncircle.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
@@ -1,4 +1,5 @@
|
||||
using FarseerPhysics;
|
||||
|
||||
using FarseerPhysics;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using FarseerPhysics.Dynamics.Joints;
|
||||
using Lidgren.Network;
|
||||
@@ -151,6 +152,11 @@ namespace Barotrauma
|
||||
set { lowPassMultiplier = MathHelper.Clamp(value, 0.0f, 1.0f); }
|
||||
}
|
||||
|
||||
public bool ObstructVision
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public float SoundRange
|
||||
{
|
||||
get { return aiTarget.SoundRange; }
|
||||
@@ -859,6 +865,7 @@ namespace Barotrauma
|
||||
if (aiTarget != null) aiTarget.SoundRange = 0.0f;
|
||||
|
||||
lowPassMultiplier = MathHelper.Lerp(lowPassMultiplier, 1.0f, 0.1f);
|
||||
ObstructVision = false;
|
||||
|
||||
if (needsAir)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Barotrauma.Lights
|
||||
|
||||
public Color AmbientLight;
|
||||
|
||||
RenderTarget2D lightMap;
|
||||
RenderTarget2D lightMap, losTexture;
|
||||
|
||||
private static Texture2D alphaClearTexture;
|
||||
|
||||
@@ -21,10 +21,9 @@ namespace Barotrauma.Lights
|
||||
|
||||
public bool LightingEnabled = true;
|
||||
|
||||
//public RenderTarget2D LightMap
|
||||
//{
|
||||
// get { return lightMap; }
|
||||
//}
|
||||
public bool ObstructVision;
|
||||
|
||||
private Texture2D visionCircle;
|
||||
|
||||
public LightManager(GraphicsDevice graphics)
|
||||
{
|
||||
@@ -32,6 +31,8 @@ namespace Barotrauma.Lights
|
||||
|
||||
AmbientLight = new Color(80, 80, 80, 255);
|
||||
|
||||
visionCircle = Sprite.LoadTexture("Content/Lights/visioncircle.png");
|
||||
|
||||
var pp = graphics.PresentationParameters;
|
||||
|
||||
lightMap = new RenderTarget2D(graphics,
|
||||
@@ -39,6 +40,7 @@ namespace Barotrauma.Lights
|
||||
pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount,
|
||||
RenderTargetUsage.DiscardContents);
|
||||
|
||||
losTexture = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
|
||||
if (alphaClearTexture==null)
|
||||
{
|
||||
@@ -56,7 +58,7 @@ namespace Barotrauma.Lights
|
||||
lights.Remove(light);
|
||||
}
|
||||
|
||||
public void DrawLOS(GraphicsDevice graphics, Camera cam, Vector2 pos)
|
||||
public void DrawLOS(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Vector2 pos)
|
||||
{
|
||||
if (!LosEnabled) return;
|
||||
|
||||
@@ -72,6 +74,11 @@ namespace Barotrauma.Lights
|
||||
convexHull.DrawShadows(graphics, cam, pos, shadowTransform);
|
||||
}
|
||||
|
||||
if (!ObstructVision) return;
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, CustomBlendStates.Multiplicative);
|
||||
spriteBatch.Draw(losTexture, Vector2.Zero);
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
||||
public void OnMapLoaded()
|
||||
@@ -140,6 +147,38 @@ namespace Barotrauma.Lights
|
||||
//clear alpha, to avoid messing stuff up later
|
||||
ClearAlphaToOne(graphics, spriteBatch);
|
||||
graphics.SetRenderTarget(null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void UpdateObstructVision(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Vector2 lookAtPosition)
|
||||
{
|
||||
|
||||
if (!ObstructVision) return;
|
||||
|
||||
graphics.SetRenderTarget(losTexture);
|
||||
graphics.Clear(Color.Black);
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, cam.Transform);
|
||||
|
||||
Vector2 diff = lookAtPosition - ViewPos;
|
||||
diff.Y = -diff.Y;
|
||||
float rotation = MathUtils.VectorToAngle(diff);
|
||||
|
||||
Vector2 scale = new Vector2(3.0f, 1.0f);
|
||||
|
||||
spriteBatch.Draw(LightSource.LightTexture, new Vector2(ViewPos.X, -ViewPos.Y), null, Color.White, rotation,
|
||||
new Vector2(LightSource.LightTexture.Width*0.2f, LightSource.LightTexture.Height/2), scale, SpriteEffects.None, 0.0f);
|
||||
spriteBatch.End();
|
||||
|
||||
//ClearAlphaToOne(graphics, spriteBatch);
|
||||
|
||||
graphics.SetRenderTarget(null);
|
||||
|
||||
//spriteBatch.Begin();
|
||||
//spriteBatch.Draw(lightMap, Vector2.Zero, Color.White);
|
||||
//spriteBatch.End();
|
||||
|
||||
}
|
||||
|
||||
private void ClearAlphaToOne(GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
|
||||
@@ -32,6 +32,19 @@ namespace Barotrauma.Lights
|
||||
}
|
||||
}
|
||||
|
||||
public static Texture2D LightTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (lightTexture == null)
|
||||
{
|
||||
lightTexture = TextureLoader.FromFile("Content/Lights/light.png");
|
||||
}
|
||||
|
||||
return lightTexture;
|
||||
}
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get { return color; }
|
||||
@@ -59,11 +72,6 @@ namespace Barotrauma.Lights
|
||||
this.range = range;
|
||||
this.color = color;
|
||||
|
||||
if (lightTexture == null)
|
||||
{
|
||||
lightTexture = TextureLoader.FromFile("Content/Lights/light.png");
|
||||
}
|
||||
|
||||
texture = lightTexture;
|
||||
|
||||
GameMain.LightManager.AddLight(this);
|
||||
@@ -82,7 +90,7 @@ namespace Barotrauma.Lights
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
Vector2 center = new Vector2(lightTexture.Width / 2, lightTexture.Height / 2);
|
||||
Vector2 center = new Vector2(LightTexture.Width / 2, LightTexture.Height / 2);
|
||||
float scale = range / (lightTexture.Width / 2.0f);
|
||||
spriteBatch.Draw(lightTexture, new Vector2(Position.X, -Position.Y), null, color, 0, center, scale, SpriteEffects.None, 1);
|
||||
}
|
||||
|
||||
@@ -161,8 +161,11 @@ namespace Barotrauma
|
||||
|
||||
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
{
|
||||
GameMain.LightManager.ObstructVision = Character.Controlled != null && Character.Controlled.ObstructVision;
|
||||
|
||||
GameMain.LightManager.UpdateLightMap(graphics, spriteBatch, cam);
|
||||
GameMain.LightManager.UpdateObstructVision(graphics, spriteBatch, cam,
|
||||
Character.Controlled==null ? LightManager.ViewPos : Character.Controlled.CursorPosition);
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//1. draw the background, characters and the parts of the submarine that are behind them
|
||||
@@ -312,7 +315,7 @@ namespace Barotrauma
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
GameMain.LightManager.DrawLOS(graphics, cam, LightManager.ViewPos);
|
||||
GameMain.LightManager.DrawLOS(graphics, spriteBatch, cam, LightManager.ViewPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user