diff --git a/.vs/Subsurface_Solution/v14/.suo b/.vs/Subsurface_Solution/v14/.suo index 69b1e8619..25aff9562 100644 Binary files a/.vs/Subsurface_Solution/v14/.suo and b/.vs/Subsurface_Solution/v14/.suo differ diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 64f70eddc..4f4db8e1c 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -515,6 +515,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Content/Items/Diving/divinggear.xml b/Subsurface/Content/Items/Diving/divinggear.xml index 016106d69..6de52afec 100644 --- a/Subsurface/Content/Items/Diving/divinggear.xml +++ b/Subsurface/Content/Items/Diving/divinggear.xml @@ -28,6 +28,8 @@ + + @@ -61,7 +63,7 @@ - + diff --git a/Subsurface/Content/Lights/visioncircle.png b/Subsurface/Content/Lights/visioncircle.png new file mode 100644 index 000000000..39ff2ecb3 Binary files /dev/null and b/Subsurface/Content/Lights/visioncircle.png differ diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 00183e073..05a63261f 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -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) { diff --git a/Subsurface/Source/Map/Lights/LightManager.cs b/Subsurface/Source/Map/Lights/LightManager.cs index b5799e9a8..de5cab385 100644 --- a/Subsurface/Source/Map/Lights/LightManager.cs +++ b/Subsurface/Source/Map/Lights/LightManager.cs @@ -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) diff --git a/Subsurface/Source/Map/Lights/LightSource.cs b/Subsurface/Source/Map/Lights/LightSource.cs index 6dd94e1ad..5bb4ced6d 100644 --- a/Subsurface/Source/Map/Lights/LightSource.cs +++ b/Subsurface/Source/Map/Lights/LightSource.cs @@ -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); } diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index 974e2bc18..6cd0d8461 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -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); } } }