Soldier flashlights!
This commit is contained in:
@@ -51,12 +51,12 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
if (ms.X < 20)
|
if (ms.X < 20)
|
||||||
Position.X += Speed * elapsed;
|
Position.X += Speed * elapsed;
|
||||||
if (ms.X > core.GraphicsDevice.Viewport.Width - 20)
|
if (ms.X > Core.GraphicsDevice.Viewport.Width - 20)
|
||||||
Position.X -= Speed * elapsed;
|
Position.X -= Speed * elapsed;
|
||||||
|
|
||||||
if (ms.Y < 20)
|
if (ms.Y < 20)
|
||||||
Position.Y += Speed * elapsed;
|
Position.Y += Speed * elapsed;
|
||||||
if (ms.Y > core.GraphicsDevice.Viewport.Height - 20)
|
if (ms.Y > Core.GraphicsDevice.Viewport.Height - 20)
|
||||||
Position.Y -= Speed * elapsed;
|
Position.Y -= Speed * elapsed;
|
||||||
|
|
||||||
int scrollChange = ms.ScrollWheelValue - lastMouseState.ScrollWheelValue;
|
int scrollChange = ms.ScrollWheelValue - lastMouseState.ScrollWheelValue;
|
||||||
|
|||||||
+86
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ namespace DepthsBelow
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Core : Microsoft.Xna.Framework.Game
|
public class Core : Microsoft.Xna.Framework.Game
|
||||||
{
|
{
|
||||||
|
public static GraphicsDevice GraphicsDevice;
|
||||||
GraphicsDeviceManager graphics;
|
GraphicsDeviceManager graphics;
|
||||||
SpriteBatch spriteBatch;
|
SpriteBatch spriteBatch;
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
this.IsMouseVisible = true;
|
this.IsMouseVisible = true;
|
||||||
|
|
||||||
KryptonEngine = new Krypton.KryptonEngine(this, "KryptonEffect");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -54,7 +55,9 @@ namespace DepthsBelow
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void Initialize()
|
protected override void Initialize()
|
||||||
{
|
{
|
||||||
// TODO: Add your initialization logic here
|
GraphicsDevice = graphics.GraphicsDevice;
|
||||||
|
|
||||||
|
KryptonEngine = new Krypton.KryptonEngine(this, "KryptonEffect");
|
||||||
|
|
||||||
// Initialize lighting engine
|
// Initialize lighting engine
|
||||||
this.KryptonEngine.Initialize();
|
this.KryptonEngine.Initialize();
|
||||||
@@ -75,16 +78,16 @@ namespace DepthsBelow
|
|||||||
protected override void LoadContent()
|
protected override void LoadContent()
|
||||||
{
|
{
|
||||||
// Create a new SpriteBatch, which can be used to draw textures.
|
// Create a new SpriteBatch, which can be used to draw textures.
|
||||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
spriteBatch = new SpriteBatch(Core.GraphicsDevice);
|
||||||
|
|
||||||
Map = Content.Load<Map>("maps/Cave.Level1");
|
Map = Content.Load<Map>("maps/Cave.Level1");
|
||||||
// Load map objects
|
// Load map objects
|
||||||
Map.Initialize(this, KryptonEngine);
|
Map.Initialize(this, KryptonEngine);
|
||||||
|
|
||||||
// DEBUG: Test lights
|
// 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),
|
Range = (float)(500),
|
||||||
Color = Color.White,
|
Color = Color.White,
|
||||||
Intensity = 1f,
|
Intensity = 1f,
|
||||||
@@ -95,10 +98,10 @@ namespace DepthsBelow
|
|||||||
IsOn = true,
|
IsOn = true,
|
||||||
ShadowType = ShadowType.Illuminated
|
ShadowType = ShadowType.Illuminated
|
||||||
};
|
};
|
||||||
this.KryptonEngine.Lights.Add(light);
|
this.KryptonEngine.Lights.Add(light);*/
|
||||||
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)(100),
|
Range = (float)(100),
|
||||||
Color = Color.White,
|
Color = Color.White,
|
||||||
Intensity = 1f,
|
Intensity = 1f,
|
||||||
@@ -145,8 +148,8 @@ namespace DepthsBelow
|
|||||||
foreach (var soldier in Squad)
|
foreach (var soldier in Squad)
|
||||||
soldier.Update(gameTime);
|
soldier.Update(gameTime);
|
||||||
|
|
||||||
foreach (Krypton.Lights.Light2D light in KryptonEngine.Lights)
|
//foreach (Krypton.Lights.Light2D light in KryptonEngine.Lights)
|
||||||
light.Position = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y));
|
// light.Position = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y));
|
||||||
|
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Camera.cs" />
|
<Compile Include="Camera.cs" />
|
||||||
|
<Compile Include="Component\Flashlight.cs" />
|
||||||
<Compile Include="Component\PathFinder.cs" />
|
<Compile Include="Component\PathFinder.cs" />
|
||||||
<Compile Include="Component\Transform.cs" />
|
<Compile Include="Component\Transform.cs" />
|
||||||
<Compile Include="Grid.cs" />
|
<Compile Include="Grid.cs" />
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ namespace DepthsBelow
|
|||||||
{
|
{
|
||||||
if (mapObject.Type == "SquadStart")
|
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<Component.Flashlight>());
|
||||||
// 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)
|
// 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 mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
|
||||||
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
public void LoadContent()
|
public void LoadContent()
|
||||||
{
|
{
|
||||||
selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1);
|
selectionTexture = new Texture2D(Core.GraphicsDevice, 1, 1);
|
||||||
selectionTexture.SetData(new Color[] { Color.White });
|
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 });
|
gridTexture.SetData(new Color[] { Color.White });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
if (checkingDirection == true)
|
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 });
|
blank.SetData(new[] { Color.White });
|
||||||
DrawLine(spriteBatch, blank, 2, Color.White, directionStart, directionNow);
|
DrawLine(spriteBatch, blank, 2, Color.White, directionStart, directionNow);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
var pfc = new PathFinder(this);
|
var pfc = new PathFinder(this);
|
||||||
AddComponent(pfc);
|
AddComponent(pfc);
|
||||||
|
|
||||||
|
AddComponent(new Flashlight(this)
|
||||||
|
{
|
||||||
|
Range = 200,
|
||||||
|
Fov = MathHelper.PiOver4
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Selected
|
public bool Selected
|
||||||
|
|||||||
@@ -51,6 +51,7 @@
|
|||||||
<Name>test</Name>
|
<Name>test</Name>
|
||||||
<Importer>TmxImporter</Importer>
|
<Importer>TmxImporter</Importer>
|
||||||
<Processor>MapProcessor</Processor>
|
<Processor>MapProcessor</Processor>
|
||||||
|
<SubType>Designer</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user