Soldier flashlights!

This commit is contained in:
Simon Holmberg
2012-10-02 01:22:04 +02:00
parent 12f795f8bf
commit e732c9a653
8 changed files with 115 additions and 16 deletions
+2 -2
View File
@@ -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;
+86
View File
@@ -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;
}
}
}
+13 -10
View File
@@ -17,6 +17,7 @@ namespace DepthsBelow
/// </summary>
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");
}
/// <summary>
@@ -54,7 +55,9 @@ namespace DepthsBelow
/// </summary>
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<Map>("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);
}
@@ -122,6 +122,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Camera.cs" />
<Compile Include="Component\Flashlight.cs" />
<Compile Include="Component\PathFinder.cs" />
<Compile Include="Component\Transform.cs" />
<Compile Include="Grid.cs" />
+3 -1
View File
@@ -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<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)
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
+3 -3
View File
@@ -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);
}
+6
View File
@@ -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
@@ -51,6 +51,7 @@
<Name>test</Name>
<Importer>TmxImporter</Importer>
<Processor>MapProcessor</Processor>
<SubType>Designer</SubType>
</Compile>
</ItemGroup>
<ItemGroup>