diff --git a/DepthsBelow/DepthsBelow/Camera.cs b/DepthsBelow/DepthsBelow/Camera.cs index d41839d..eebcc25 100644 --- a/DepthsBelow/DepthsBelow/Camera.cs +++ b/DepthsBelow/DepthsBelow/Camera.cs @@ -51,12 +51,12 @@ namespace DepthsBelow if (ms.X < 20) Position.X += Speed * elapsed; - if (ms.X > core.GraphicsDevice.Viewport.Width - 20) + if (ms.X > Core.GraphicsDevice.Viewport.Width - 20) Position.X -= Speed * elapsed; if (ms.Y < 20) Position.Y += Speed * elapsed; - if (ms.Y > core.GraphicsDevice.Viewport.Height - 20) + if (ms.Y > Core.GraphicsDevice.Viewport.Height - 20) Position.Y -= Speed * elapsed; int scrollChange = ms.ScrollWheelValue - lastMouseState.ScrollWheelValue; diff --git a/DepthsBelow/DepthsBelow/Component/Flashlight.cs b/DepthsBelow/DepthsBelow/Component/Flashlight.cs new file mode 100755 index 0000000..f69d1fc --- /dev/null +++ b/DepthsBelow/DepthsBelow/Component/Flashlight.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; + +namespace DepthsBelow.Component +{ + public class Flashlight : Component + { + public float Range + { + get { return KryptonLight.Range; } + set { KryptonLight.Range = value; } + } + public float Fov + { + get { return KryptonLight.Fov; } + set { KryptonLight.Fov = value; } + } + public float Intensity + { + get { return KryptonLight.Intensity; } + set { KryptonLight.Intensity = value; } + } + public float Angle + { + get { return KryptonLight.Angle; } + set { KryptonLight.Angle = value; } + } + public Vector2 Position + { + get { return KryptonLight.Position; } + set { KryptonLight.Position = value; } + } + + public Color Color + { + get { return KryptonLight.Color; } + set { KryptonLight.Color = value; } + } + + public bool IsOn + { + get { return KryptonLight.IsOn; } + set { KryptonLight.IsOn = value; } + } + + public Krypton.Lights.ShadowType ShadowType + { + get { return KryptonLight.ShadowType; } + set { KryptonLight.ShadowType = value; } + } + + public Krypton.Lights.Light2D KryptonLight; + + public Flashlight(Entity parent) + : base(parent) + { + KryptonLight = new Krypton.Lights.Light2D() + { + Texture = Krypton.LightTextureBuilder.CreatePointLight(Core.GraphicsDevice, 512), + Range = (float)(100), + Position = parent.Transform.World + Parent.Transform.World.Origin, + Angle = parent.Transform.World.Rotation, + Color = Color.White, + Intensity = 1f, + Fov = MathHelper.TwoPi, + IsOn = true, + ShadowType = Krypton.Lights.ShadowType.Illuminated + }; + } + + public static explicit operator Krypton.Lights.Light2D(Flashlight flashlight) + { + return flashlight.KryptonLight; + } + + public override void Update(GameTime gameTime) + { + Position = Parent.Transform.World + Parent.Transform.World.Origin; + Angle = Parent.Transform.World.Rotation; + } + + } +} diff --git a/DepthsBelow/DepthsBelow/Core.cs b/DepthsBelow/DepthsBelow/Core.cs index 778e2c5..8ead385 100755 --- a/DepthsBelow/DepthsBelow/Core.cs +++ b/DepthsBelow/DepthsBelow/Core.cs @@ -17,6 +17,7 @@ namespace DepthsBelow /// public class Core : Microsoft.Xna.Framework.Game { + public static GraphicsDevice GraphicsDevice; GraphicsDeviceManager graphics; SpriteBatch spriteBatch; @@ -43,7 +44,7 @@ namespace DepthsBelow this.IsMouseVisible = true; - KryptonEngine = new Krypton.KryptonEngine(this, "KryptonEffect"); + } /// @@ -54,7 +55,9 @@ namespace DepthsBelow /// protected override void Initialize() { - // TODO: Add your initialization logic here + GraphicsDevice = graphics.GraphicsDevice; + + KryptonEngine = new Krypton.KryptonEngine(this, "KryptonEffect"); // Initialize lighting engine this.KryptonEngine.Initialize(); @@ -75,16 +78,16 @@ namespace DepthsBelow protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. - spriteBatch = new SpriteBatch(GraphicsDevice); + spriteBatch = new SpriteBatch(Core.GraphicsDevice); Map = Content.Load("maps/Cave.Level1"); // Load map objects Map.Initialize(this, KryptonEngine); // DEBUG: Test lights - var light = new Krypton.Lights.Light2D() + /*var light = new Krypton.Lights.Light2D() { - Texture = Krypton.LightTextureBuilder.CreatePointLight(this.GraphicsDevice, 512), + Texture = Krypton.LightTextureBuilder.CreatePointLight(Core.GraphicsDevice, 512), Range = (float)(500), Color = Color.White, Intensity = 1f, @@ -95,10 +98,10 @@ namespace DepthsBelow IsOn = true, ShadowType = ShadowType.Illuminated }; - this.KryptonEngine.Lights.Add(light); - light = new Krypton.Lights.Light2D() + this.KryptonEngine.Lights.Add(light);*/ + var light = new Krypton.Lights.Light2D() { - Texture = Krypton.LightTextureBuilder.CreatePointLight(this.GraphicsDevice, 512), + Texture = Krypton.LightTextureBuilder.CreatePointLight(Core.GraphicsDevice, 512), Range = (float)(100), Color = Color.White, Intensity = 1f, @@ -145,8 +148,8 @@ namespace DepthsBelow foreach (var soldier in Squad) soldier.Update(gameTime); - foreach (Krypton.Lights.Light2D light in KryptonEngine.Lights) - light.Position = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y)); + //foreach (Krypton.Lights.Light2D light in KryptonEngine.Lights) + // light.Position = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y)); base.Update(gameTime); } diff --git a/DepthsBelow/DepthsBelow/DepthsBelow.csproj b/DepthsBelow/DepthsBelow/DepthsBelow.csproj index 9cf179b..75513dd 100644 --- a/DepthsBelow/DepthsBelow/DepthsBelow.csproj +++ b/DepthsBelow/DepthsBelow/DepthsBelow.csproj @@ -122,6 +122,7 @@ + diff --git a/DepthsBelow/DepthsBelow/Map.cs b/DepthsBelow/DepthsBelow/Map.cs index 00dc2f0..b14446e 100755 --- a/DepthsBelow/DepthsBelow/Map.cs +++ b/DepthsBelow/DepthsBelow/Map.cs @@ -86,7 +86,9 @@ namespace DepthsBelow { if (mapObject.Type == "SquadStart") { - var soldier = new Soldier(core, ref core.Squad); + // HACK: Move the entity creation to an entity factory + var soldier = new Soldier(core, ref core.Squad); + core.KryptonEngine.Lights.Add((Krypton.Lights.Light2D)soldier.GetComponent()); // HACK: For some reason, the tile object coordinates are offset by one tile on the Y-axis in the Tiled map file (https://github.com/bjorn/tiled/issues/91) var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); diff --git a/DepthsBelow/DepthsBelow/MouseInput.cs b/DepthsBelow/DepthsBelow/MouseInput.cs index b8d911a..3470825 100755 --- a/DepthsBelow/DepthsBelow/MouseInput.cs +++ b/DepthsBelow/DepthsBelow/MouseInput.cs @@ -36,10 +36,10 @@ namespace DepthsBelow public void LoadContent() { - selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1); + selectionTexture = new Texture2D(Core.GraphicsDevice, 1, 1); selectionTexture.SetData(new Color[] { Color.White }); - gridTexture = new Texture2D(core.GraphicsDevice, 1, 1); + gridTexture = new Texture2D(Core.GraphicsDevice, 1, 1); gridTexture.SetData(new Color[] { Color.White }); } @@ -153,7 +153,7 @@ namespace DepthsBelow if (checkingDirection == true) { - Texture2D blank = new Texture2D(core.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); + Texture2D blank = new Texture2D(Core.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); blank.SetData(new[] { Color.White }); DrawLine(spriteBatch, blank, 2, Color.White, directionStart, directionNow); } diff --git a/DepthsBelow/DepthsBelow/Soldier.cs b/DepthsBelow/DepthsBelow/Soldier.cs index 336e7c6..66229d2 100644 --- a/DepthsBelow/DepthsBelow/Soldier.cs +++ b/DepthsBelow/DepthsBelow/Soldier.cs @@ -36,6 +36,12 @@ namespace DepthsBelow var pfc = new PathFinder(this); AddComponent(pfc); + + AddComponent(new Flashlight(this) + { + Range = 200, + Fov = MathHelper.PiOver4 + }); } public bool Selected diff --git a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj index 63b1f25..f35259c 100644 --- a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj +++ b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj @@ -51,6 +51,7 @@ test TmxImporter MapProcessor + Designer