Monsters turn in direction walking

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-10-27 15:53:02 +02:00
parent 7d42fb1bf0
commit 5c59a2277b
4 changed files with 633 additions and 612 deletions
+89 -83
View File
@@ -19,33 +19,33 @@ namespace DepthsBelow
/// </summary> /// </summary>
public class Core : Microsoft.Xna.Framework.Game public class Core : Microsoft.Xna.Framework.Game
{ {
public static GraphicsDeviceManager GraphicsDeviceManager; public static GraphicsDeviceManager GraphicsDeviceManager;
private SpriteBatch spriteBatch; private SpriteBatch spriteBatch;
private Effect lightShader; private Effect lightShader;
private RenderTarget2D lightRenderTarget; private RenderTarget2D lightRenderTarget;
private RenderTarget2D sceneRenderTarget; private RenderTarget2D sceneRenderTarget;
public Lua Lua; public Lua Lua;
public EntityManager EntityManager; public EntityManager EntityManager;
public TurnManager TurnManager; public TurnManager TurnManager;
public Camera Camera; public Camera Camera;
public Interface Interface; public Interface Interface;
public static MouseInput MouseInput; public static MouseInput MouseInput;
public static KeyboardInput KeyboardInput; public static KeyboardInput KeyboardInput;
public List<Soldier> Squad; public List<Soldier> Squad;
public DynamicGroupManager GroupManager; public DynamicGroupManager GroupManager;
public List<SmallEnemy> Swarm; public List<SmallEnemy> Swarm;
public List<Shot> Volley; public List<Shot> Volley;
public List<MonsterSpawn> Spawn; public List<MonsterSpawn> Spawn;
public static Map Map; public static Map Map;
public SmallEnemy TestMonster; public SmallEnemy TestMonster;
public int Brightness = 30; public int Brightness = 30;
public Core() public Core()
@@ -70,24 +70,24 @@ namespace DepthsBelow
/// and initialize them as well. /// and initialize them as well.
/// </summary> /// </summary>
protected override void Initialize() protected override void Initialize()
{ {
GameServices.AddService<GraphicsDevice>(GraphicsDevice); GameServices.AddService<GraphicsDevice>(GraphicsDevice);
GameServices.AddService<ContentManager>(Content); GameServices.AddService<ContentManager>(Content);
Lua = new Lua(); Lua = new Lua();
EntityManager = new EntityManager(); EntityManager = new EntityManager();
TurnManager = new TurnManager(new string[] { "Player", "Computer" }); TurnManager = new TurnManager(new string[] { "Player", "Computer" });
Camera = new Camera(this); Camera = new Camera(this);
Interface = new Interface(this); Interface = new Interface(this);
Squad = new List<Soldier>(); Squad = new List<Soldier>();
Swarm = new List<SmallEnemy>(); Swarm = new List<SmallEnemy>();
Volley = new List<Shot>(); Volley = new List<Shot>();
Spawn = new List<MonsterSpawn>(); Spawn = new List<MonsterSpawn>();
base.Initialize(); base.Initialize();
} }
@@ -98,15 +98,21 @@ 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(GraphicsDevice);
lightShader = Content.Load<Effect>("shaders/LightEffect"); lightShader = Content.Load<Effect>("shaders/LightEffect");
lightRenderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); lightRenderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
sceneRenderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); sceneRenderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
Map = Content.Load<Map>("maps/Aztek.Test"); Map = Content.Load<Map>("maps/Aztek.Test");
//Map = Content.Load<Map>("maps/Cave.Level1");
// Load map objects // Load map objects
Map.ParseObjects(this); Map.ParseObjects(this);
GroupManager = new DynamicGroupManager(Squad.Cast<Entity>().ToList(), (float)Grid.TileSize * 1.5f); GroupManager = new DynamicGroupManager(Squad.Cast<Entity>().ToList(), (float)Grid.TileSize * 1.5f);
Squad[0].Name = "Dean H. Jones";
Squad[1].Name = "Walter L. Verville";
Squad[2].Name = "Patrick Y. Southerland";
Squad[3].Name = "Andrew C. Friend";
Squad[4].Name = "Gary B. Whitley";
Interface.CreateUnitFrames(Squad); Interface.CreateUnitFrames(Squad);
// TODO: use this.Content to load your game content here // TODO: use this.Content to load your game content here
@@ -116,12 +122,12 @@ namespace DepthsBelow
MouseInput = new MouseInput(this); MouseInput = new MouseInput(this);
MouseInput.LoadContent(); MouseInput.LoadContent();
KeyboardInput = new KeyboardInput(this); KeyboardInput = new KeyboardInput(this);
TestMonster = new SmallEnemy(EntityManager, ref Swarm); TestMonster = new SmallEnemy(EntityManager, ref Swarm);
TestMonster.X = 12; TestMonster.X = 12;
TestMonster.Y = 4; TestMonster.Y = 4;
Swarm.Add(TestMonster); Swarm.Add(TestMonster);
// Load Lua scripts after everything is created // Load Lua scripts after everything is created
Lua.LoadScripts(); Lua.LoadScripts();
@@ -163,25 +169,25 @@ namespace DepthsBelow
/// This is called when the game should draw itself. /// This is called when the game should draw itself.
/// </summary> /// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param> /// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime) protected override void Draw(GameTime gameTime)
{ {
MouseState ms = Mouse.GetState(); MouseState ms = Mouse.GetState();
// Draw to the lighting render target // Draw to the lighting render target
GraphicsDevice.SetRenderTarget(lightRenderTarget); GraphicsDevice.SetRenderTarget(lightRenderTarget);
GraphicsDevice.Clear(new Color(Brightness, Brightness, Brightness)); GraphicsDevice.Clear(new Color(Brightness, Brightness, Brightness));
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.PointClamp, null, null, null, spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.PointClamp, null, null, null,
Camera.Transform); Camera.Transform);
// Draw flashlights // Draw flashlights
foreach (var light in EntityManager.GetComponents<Component.Flashlight>()) foreach (var light in EntityManager.GetComponents<Component.Flashlight>())
light.Draw(spriteBatch); light.Draw(spriteBatch);
spriteBatch.End(); spriteBatch.End();
GraphicsDevice.SetRenderTarget(null); GraphicsDevice.SetRenderTarget(null);
// Draw the scene to a render target // Draw the scene to a render target
GraphicsDevice.SetRenderTarget(sceneRenderTarget); GraphicsDevice.SetRenderTarget(sceneRenderTarget);
GraphicsDevice.Clear(Color.Black); GraphicsDevice.Clear(Color.Black);
// Start drawing using the Camera transform // Start drawing using the Camera transform
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null, null, spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null, null,
@@ -190,45 +196,45 @@ namespace DepthsBelow
// Draw the level // Draw the level
Map.Draw(spriteBatch); Map.Draw(spriteBatch);
// Draw entities // Draw entities
foreach (var spriteRenderer in EntityManager.GetComponents<Component.SpriteRenderer>()) foreach (var spriteRenderer in EntityManager.GetComponents<Component.SpriteRenderer>())
{ {
// Only render illuminated entities // Only render illuminated entities
var position = Camera.WorldToScreen(spriteRenderer.Parent.Transform.World + spriteRenderer.Parent.Transform.World.Origin); var position = Camera.WorldToScreen(spriteRenderer.Parent.Transform.World + spriteRenderer.Parent.Transform.World.Origin);
var sourceRect = new Rectangle((int)position.X, (int)position.Y, 1, 1); var sourceRect = new Rectangle((int)position.X, (int)position.Y, 1, 1);
if ( if (
sourceRect.X >= 0 sourceRect.X >= 0
&& sourceRect.Y >= 0 && sourceRect.Y >= 0
&& sourceRect.X < lightRenderTarget.Width && sourceRect.X < lightRenderTarget.Width
&& sourceRect.Y < lightRenderTarget.Height && sourceRect.Y < lightRenderTarget.Height
) )
{ {
var lightData = new Color[1]; var lightData = new Color[1];
lightRenderTarget.GetData<Color>(0, sourceRect, lightData, 0, 1); lightRenderTarget.GetData<Color>(0, sourceRect, lightData, 0, 1);
if (lightData[0] != new Color(Brightness, Brightness, Brightness)) if (lightData[0] != new Color(Brightness, Brightness, Brightness))
spriteRenderer.Draw(spriteBatch); spriteRenderer.Draw(spriteBatch);
} }
} }
#if DEBUG #if DEBUG
var debugTexture = new Texture2D(GraphicsDevice, 1, 1); var debugTexture = new Texture2D(GraphicsDevice, 1, 1);
debugTexture.SetData(new Color[] { Color.White }); debugTexture.SetData(new Color[] { Color.White });
foreach (var collisionComponent in EntityManager.GetComponents<Component.Collision>()) foreach (var collisionComponent in EntityManager.GetComponents<Component.Collision>())
{ {
spriteBatch.Draw(debugTexture, collisionComponent.Rectangle, Color.Red * 0.5f); spriteBatch.Draw(debugTexture, collisionComponent.Rectangle, Color.Red * 0.5f);
} }
#endif #endif
// Draw mouse input visuals // Draw mouse input visuals
MouseInput.Draw(spriteBatch); MouseInput.Draw(spriteBatch);
spriteBatch.End(); spriteBatch.End();
GraphicsDevice.SetRenderTarget(null); GraphicsDevice.SetRenderTarget(null);
// Draw the scene from the render target with the light shader // Draw the scene from the render target with the light shader
lightShader.Parameters["LightsTexture"].SetValue(lightRenderTarget); lightShader.Parameters["LightsTexture"].SetValue(lightRenderTarget);
lightShader.CurrentTechnique.Passes[0].Apply(); lightShader.CurrentTechnique.Passes[0].Apply();
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, null, null, lightShader, spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, null, null, lightShader,
Matrix.Identity); Matrix.Identity);
spriteBatch.Draw(sceneRenderTarget, Vector2.Zero, Color.White); spriteBatch.Draw(sceneRenderTarget, Vector2.Zero, Color.White);
spriteBatch.End(); spriteBatch.End();
File diff suppressed because it is too large Load Diff
+8 -4
View File
@@ -105,10 +105,10 @@ namespace DepthsBelow
{ {
KeyboardState ks = Keyboard.GetState(); KeyboardState ks = Keyboard.GetState();
// Brightness // Brightness
if (ks.IsKeyUp(Keys.Up) && lastKeyboardState.IsKeyDown(Keys.Up)) if (ks.IsKeyUp(Keys.Up) && lastKeyboardState.IsKeyDown(Keys.Up))
core.Brightness = (int)MathHelper.Clamp(core.Brightness + 5, 0, 254); core.Brightness = (int)MathHelper.Clamp(core.Brightness + 5, 0, 254);
if (ks.IsKeyUp(Keys.Down) && lastKeyboardState.IsKeyDown(Keys.Down)) if (ks.IsKeyUp(Keys.Down) && lastKeyboardState.IsKeyDown(Keys.Down))
core.Brightness = (int)MathHelper.Clamp(core.Brightness - 5, 0, 254); core.Brightness = (int)MathHelper.Clamp(core.Brightness - 5, 0, 254);
// Debug test: grouping // Debug test: grouping
@@ -177,6 +177,10 @@ namespace DepthsBelow
}*/ }*/
core.TestMonster.X = 12; core.TestMonster.X = 12;
core.TestMonster.Y = 4; core.TestMonster.Y = 4;
}
if (ks.IsKeyDown(Keys.N))
{
} }
if (ks.IsKeyDown(Keys.S)) if (ks.IsKeyDown(Keys.S))
{ {
+26 -15
View File
@@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using DepthsBelow.Component; using DepthsBelow.Component;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
@@ -31,7 +31,7 @@ namespace DepthsBelow
} }
} }
public SmallEnemy(EntityManager entityManager, ref List<SmallEnemy> swarm) public SmallEnemy(EntityManager entityManager, ref List<SmallEnemy> swarm)
: base(entityManager) : base(entityManager)
{ {
if (Texture == null) if (Texture == null)
@@ -49,16 +49,16 @@ namespace DepthsBelow
AddComponent(cc); AddComponent(cc);
var pfc = new PathFinder(this); var pfc = new PathFinder(this);
AddComponent(pfc); AddComponent(pfc);
var stat = new Component.Stat(this) var stat = new Component.Stat(this)
{ {
Life = 2, Life = 2,
Defence = 0, Defence = 0,
Strength = 5000, Strength = 5000,
GetAim = 100, GetAim = 100,
GetDodge = 50 GetDodge = 50
}; };
AddComponent(stat); AddComponent(stat);
} }
@@ -73,7 +73,7 @@ namespace DepthsBelow
} }
public static void LoadContent() public static void LoadContent()
{ {
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Monster"); Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Monster");
} }
@@ -111,14 +111,25 @@ namespace DepthsBelow
// HACK: Make this work properly with other speeds... // HACK: Make this work properly with other speeds...
float speed = 4f; float speed = 4f;
if (Transform.World.X < nodeWorldPos.X) if (Transform.World.X < nodeWorldPos.X)
{
Transform.World.X += speed; Transform.World.X += speed;
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(0);
}
if (Transform.World.X > nodeWorldPos.X) if (Transform.World.X > nodeWorldPos.X)
{
Transform.World.X -= speed; Transform.World.X -= speed;
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(180);
}
if (Transform.World.Y < nodeWorldPos.Y) if (Transform.World.Y < nodeWorldPos.Y)
{
Transform.World.Y += speed; Transform.World.Y += speed;
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(90);
}
if (Transform.World.Y > nodeWorldPos.Y) if (Transform.World.Y > nodeWorldPos.Y)
{
Transform.World.Y -= speed; Transform.World.Y -= speed;
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(270);
}
if (Transform.World == nodeWorldPos) if (Transform.World == nodeWorldPos)
{ {
if (currentStep < numberOfSteps) if (currentStep < numberOfSteps)