Monster som inte dyker upp förren runda X
This almost looks like a game now!
This commit is contained in:
+256
-256
@@ -1,256 +1,256 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using DepthsBelow.GUI;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.GamerServices;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Microsoft.Xna.Framework.Media;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the main type for your game
|
||||
/// </summary>
|
||||
public class Core : Microsoft.Xna.Framework.Game
|
||||
{
|
||||
public static GraphicsDeviceManager GraphicsDeviceManager;
|
||||
private SpriteBatch spriteBatch;
|
||||
private Effect lightShader;
|
||||
private RenderTarget2D lightRenderTarget;
|
||||
private RenderTarget2D sceneRenderTarget;
|
||||
|
||||
public Lua Lua;
|
||||
|
||||
public TurnManager TurnManager;
|
||||
|
||||
public Camera Camera;
|
||||
public Interface Interface;
|
||||
|
||||
public/* static*/ MouseInput MouseInput;
|
||||
public static KeyboardInput KeyboardInput;
|
||||
public List<Soldier> Squad;
|
||||
public DynamicGroupManager GroupManager;
|
||||
public List<SmallEnemy> Swarm;
|
||||
public List<Shot> Volley;
|
||||
|
||||
public List<MonsterSpawn> Spawn;
|
||||
|
||||
public static Map Map;
|
||||
|
||||
public SmallEnemy TestMonster;
|
||||
|
||||
public int Brightness = 30;
|
||||
|
||||
public Core()
|
||||
{
|
||||
GraphicsDeviceManager = new GraphicsDeviceManager(this);
|
||||
GraphicsDeviceManager.PreferredBackBufferWidth = 1280;
|
||||
GraphicsDeviceManager.PreferredBackBufferHeight = 720;
|
||||
GraphicsDeviceManager.IsFullScreen = false;
|
||||
//graphics.SynchronizeWithVerticalRetrace = false;
|
||||
GraphicsDeviceManager.ApplyChanges();
|
||||
|
||||
this.IsFixedTimeStep = false;
|
||||
this.IsMouseVisible = true;
|
||||
|
||||
Content.RootDirectory = "Content";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows the game to perform any initialization it needs to before starting to run.
|
||||
/// This is where it can query for any required services and load any non-graphic
|
||||
/// related content. Calling base.Initialize will enumerate through any components
|
||||
/// and initialize them as well.
|
||||
/// </summary>
|
||||
protected override void Initialize()
|
||||
{
|
||||
GameServices.AddService<GraphicsDevice>(GraphicsDevice);
|
||||
GameServices.AddService<ContentManager>(Content);
|
||||
|
||||
Lua = new Lua();
|
||||
|
||||
TurnManager = new TurnManager(new string[] { "Player", "Computer" });
|
||||
|
||||
Camera = new Camera(this);
|
||||
Interface = new Interface(this);
|
||||
|
||||
Squad = new List<Soldier>();
|
||||
Swarm = new List<SmallEnemy>();
|
||||
Volley = new List<Shot>();
|
||||
|
||||
Spawn = new List<MonsterSpawn>();
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LoadContent will be called once per game and is the place to load
|
||||
/// all of your content.
|
||||
/// </summary>
|
||||
protected override void LoadContent()
|
||||
{
|
||||
// Create a new SpriteBatch, which can be used to draw textures.
|
||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
lightShader = Content.Load<Effect>("shaders/LightEffect");
|
||||
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);
|
||||
|
||||
Map = Content.Load<Map>("maps/prototyp");
|
||||
//Map = Content.Load<Map>("maps/Aztek.Test");
|
||||
//Map = Content.Load<Map>("maps/Cave.Level1");
|
||||
|
||||
// Load map objects
|
||||
Map.ParseObjects(this);
|
||||
|
||||
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";
|
||||
|
||||
// Center the camera on a unit
|
||||
Camera.Position = Squad[0].Transform.World.Position * -1 + new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
|
||||
|
||||
GroupManager = new DynamicGroupManager(Squad.Cast<Entity>().ToList(), (float)Grid.TileSize * 1.5f);
|
||||
|
||||
Interface.CreateUnitFrames(Squad);
|
||||
|
||||
// TODO: use this.Content to load your game content here
|
||||
Soldier.LoadContent();
|
||||
SmallEnemy.LoadContent();
|
||||
//Shot.LoadContent();
|
||||
|
||||
MouseInput = new MouseInput(this);
|
||||
MouseInput.LoadContent();
|
||||
KeyboardInput = new KeyboardInput(this);
|
||||
|
||||
TestMonster = new SmallEnemy(ref Swarm);
|
||||
TestMonster.X = 12;
|
||||
TestMonster.Y = 4;
|
||||
Swarm.Add(TestMonster);
|
||||
|
||||
// Load Lua scripts after everything is created
|
||||
Lua.LoadScripts();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UnloadContent will be called once per game and is the place to unload
|
||||
/// all content.
|
||||
/// </summary>
|
||||
protected override void UnloadContent()
|
||||
{
|
||||
// TODO: Unload any non ContentManager content here
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows the game to run logic such as updating the world,
|
||||
/// checking for collisions, gathering input, and playing audio.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
// Allows the game to exit
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
||||
this.Exit();
|
||||
|
||||
Camera.Update(gameTime);
|
||||
MouseInput.Update(gameTime);
|
||||
KeyboardInput.Update(gameTime);
|
||||
|
||||
EntityManager.Update(gameTime);
|
||||
|
||||
Interface.Update(gameTime);
|
||||
GUIManager.Update(gameTime);
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is called when the game should draw itself.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
MouseState ms = Mouse.GetState();
|
||||
|
||||
// Draw to the lighting render target
|
||||
GraphicsDevice.SetRenderTarget(lightRenderTarget);
|
||||
GraphicsDevice.Clear(new Color(Brightness, Brightness, Brightness));
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.PointClamp, null, null, null,
|
||||
Camera.Transform);
|
||||
|
||||
// Draw flashlights
|
||||
foreach (var light in EntityManager.GetComponents<Component.Flashlight>())
|
||||
light.Draw(spriteBatch);
|
||||
|
||||
spriteBatch.End();
|
||||
GraphicsDevice.SetRenderTarget(null);
|
||||
|
||||
// Draw the scene to a render target
|
||||
GraphicsDevice.SetRenderTarget(sceneRenderTarget);
|
||||
GraphicsDevice.Clear(Color.Black);
|
||||
// Start drawing using the Camera transform
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null, null,
|
||||
Camera.Transform);
|
||||
|
||||
// Draw the level
|
||||
Map.Draw(spriteBatch);
|
||||
|
||||
// Draw entities
|
||||
foreach (var spriteRenderer in EntityManager.GetComponents<Component.SpriteRenderer>())
|
||||
{
|
||||
// Only render illuminated entities
|
||||
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);
|
||||
if (
|
||||
sourceRect.X >= 0
|
||||
&& sourceRect.Y >= 0
|
||||
&& sourceRect.X < lightRenderTarget.Width
|
||||
&& sourceRect.Y < lightRenderTarget.Height
|
||||
)
|
||||
{
|
||||
var lightData = new Color[1];
|
||||
lightRenderTarget.GetData<Color>(0, sourceRect, lightData, 0, 1);
|
||||
if (lightData[0] != new Color(Brightness, Brightness, Brightness))
|
||||
spriteRenderer.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
var debugTexture = new Texture2D(GraphicsDevice, 1, 1);
|
||||
debugTexture.SetData(new Color[] { Color.White });
|
||||
foreach (var collisionComponent in EntityManager.GetComponents<Component.Collision>())
|
||||
{
|
||||
spriteBatch.Draw(debugTexture, collisionComponent.Rectangle, Color.Red * 0.5f);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Draw mouse input visuals
|
||||
MouseInput.Draw(spriteBatch);
|
||||
|
||||
spriteBatch.End();
|
||||
GraphicsDevice.SetRenderTarget(null);
|
||||
|
||||
// Draw the scene from the render target with the light shader
|
||||
lightShader.Parameters["LightsTexture"].SetValue(lightRenderTarget);
|
||||
lightShader.CurrentTechnique.Passes[0].Apply();
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, null, null, lightShader,
|
||||
Matrix.Identity);
|
||||
spriteBatch.Draw(sceneRenderTarget, Vector2.Zero, Color.White);
|
||||
spriteBatch.End();
|
||||
|
||||
// Draw GUI components
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, null, null, null, Matrix.Identity);
|
||||
GUIManager.Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using DepthsBelow.GUI;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.GamerServices;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Microsoft.Xna.Framework.Media;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the main type for your game
|
||||
/// </summary>
|
||||
public class Core : Microsoft.Xna.Framework.Game
|
||||
{
|
||||
public static GraphicsDeviceManager GraphicsDeviceManager;
|
||||
private SpriteBatch spriteBatch;
|
||||
private Effect lightShader;
|
||||
private RenderTarget2D lightRenderTarget;
|
||||
private RenderTarget2D sceneRenderTarget;
|
||||
|
||||
public Lua Lua;
|
||||
|
||||
public TurnManager TurnManager;
|
||||
|
||||
public Camera Camera;
|
||||
public Interface Interface;
|
||||
|
||||
public/* static*/ MouseInput MouseInput;
|
||||
public static KeyboardInput KeyboardInput;
|
||||
public List<Soldier> Squad;
|
||||
public DynamicGroupManager GroupManager;
|
||||
public List<SmallEnemy> Swarm;
|
||||
public List<Shot> Volley;
|
||||
|
||||
public List<MonsterSpawn> Spawn;
|
||||
|
||||
public static Map Map;
|
||||
|
||||
public SmallEnemy TestMonster;
|
||||
|
||||
public int Brightness = 30;
|
||||
|
||||
public Core()
|
||||
{
|
||||
GraphicsDeviceManager = new GraphicsDeviceManager(this);
|
||||
GraphicsDeviceManager.PreferredBackBufferWidth = 1280;
|
||||
GraphicsDeviceManager.PreferredBackBufferHeight = 720;
|
||||
GraphicsDeviceManager.IsFullScreen = false;
|
||||
//graphics.SynchronizeWithVerticalRetrace = false;
|
||||
GraphicsDeviceManager.ApplyChanges();
|
||||
|
||||
this.IsFixedTimeStep = false;
|
||||
this.IsMouseVisible = true;
|
||||
|
||||
Content.RootDirectory = "Content";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows the game to perform any initialization it needs to before starting to run.
|
||||
/// This is where it can query for any required services and load any non-graphic
|
||||
/// related content. Calling base.Initialize will enumerate through any components
|
||||
/// and initialize them as well.
|
||||
/// </summary>
|
||||
protected override void Initialize()
|
||||
{
|
||||
GameServices.AddService<GraphicsDevice>(GraphicsDevice);
|
||||
GameServices.AddService<ContentManager>(Content);
|
||||
|
||||
Lua = new Lua();
|
||||
|
||||
TurnManager = new TurnManager(new string[] { "Player", "Computer" });
|
||||
|
||||
Camera = new Camera(this);
|
||||
Interface = new Interface(this);
|
||||
|
||||
Squad = new List<Soldier>();
|
||||
Swarm = new List<SmallEnemy>();
|
||||
Volley = new List<Shot>();
|
||||
|
||||
Spawn = new List<MonsterSpawn>();
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LoadContent will be called once per game and is the place to load
|
||||
/// all of your content.
|
||||
/// </summary>
|
||||
protected override void LoadContent()
|
||||
{
|
||||
// Create a new SpriteBatch, which can be used to draw textures.
|
||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
lightShader = Content.Load<Effect>("shaders/LightEffect");
|
||||
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);
|
||||
|
||||
Map = Content.Load<Map>("maps/prototyp");
|
||||
//Map = Content.Load<Map>("maps/Aztek.Test");
|
||||
//Map = Content.Load<Map>("maps/Cave.Level1");
|
||||
|
||||
// Load map objects
|
||||
Map.ParseObjects(this);
|
||||
|
||||
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";
|
||||
|
||||
// Center the camera on a unit
|
||||
Camera.Position = Squad[0].Transform.World.Position * -1 + new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
|
||||
|
||||
GroupManager = new DynamicGroupManager(Squad.Cast<Entity>().ToList(), (float)Grid.TileSize * 1.5f);
|
||||
|
||||
Interface.CreateUnitFrames(Squad);
|
||||
|
||||
// TODO: use this.Content to load your game content here
|
||||
Soldier.LoadContent();
|
||||
SmallEnemy.LoadContent();
|
||||
//Shot.LoadContent();
|
||||
|
||||
MouseInput = new MouseInput(this);
|
||||
MouseInput.LoadContent();
|
||||
KeyboardInput = new KeyboardInput(this);
|
||||
|
||||
TestMonster = new SmallEnemy(ref Swarm);
|
||||
TestMonster.X = 12;
|
||||
TestMonster.Y = 4;
|
||||
Swarm.Add(TestMonster);
|
||||
|
||||
// Load Lua scripts after everything is created
|
||||
Lua.LoadScripts();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UnloadContent will be called once per game and is the place to unload
|
||||
/// all content.
|
||||
/// </summary>
|
||||
protected override void UnloadContent()
|
||||
{
|
||||
// TODO: Unload any non ContentManager content here
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows the game to run logic such as updating the world,
|
||||
/// checking for collisions, gathering input, and playing audio.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
// Allows the game to exit
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
||||
this.Exit();
|
||||
|
||||
Camera.Update(gameTime);
|
||||
MouseInput.Update(gameTime);
|
||||
KeyboardInput.Update(gameTime);
|
||||
|
||||
EntityManager.Update(gameTime);
|
||||
|
||||
Interface.Update(gameTime);
|
||||
GUIManager.Update(gameTime);
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is called when the game should draw itself.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
MouseState ms = Mouse.GetState();
|
||||
|
||||
// Draw to the lighting render target
|
||||
GraphicsDevice.SetRenderTarget(lightRenderTarget);
|
||||
GraphicsDevice.Clear(new Color(Brightness, Brightness, Brightness));
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.PointClamp, null, null, null,
|
||||
Camera.Transform);
|
||||
|
||||
// Draw flashlights
|
||||
foreach (var light in EntityManager.GetComponents<Component.Flashlight>())
|
||||
light.Draw(spriteBatch);
|
||||
|
||||
spriteBatch.End();
|
||||
GraphicsDevice.SetRenderTarget(null);
|
||||
|
||||
// Draw the scene to a render target
|
||||
GraphicsDevice.SetRenderTarget(sceneRenderTarget);
|
||||
GraphicsDevice.Clear(Color.Black);
|
||||
// Start drawing using the Camera transform
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null, null,
|
||||
Camera.Transform);
|
||||
|
||||
// Draw the level
|
||||
Map.Draw(spriteBatch);
|
||||
|
||||
// Draw entities
|
||||
foreach (var spriteRenderer in EntityManager.GetComponents<Component.SpriteRenderer>())
|
||||
{
|
||||
// Only render illuminated entities
|
||||
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);
|
||||
if (
|
||||
sourceRect.X >= 0
|
||||
&& sourceRect.Y >= 0
|
||||
&& sourceRect.X < lightRenderTarget.Width
|
||||
&& sourceRect.Y < lightRenderTarget.Height
|
||||
)
|
||||
{
|
||||
var lightData = new Color[1];
|
||||
lightRenderTarget.GetData<Color>(0, sourceRect, lightData, 0, 1);
|
||||
if (lightData[0] != new Color(Brightness, Brightness, Brightness))
|
||||
spriteRenderer.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
|
||||
/*#if DEBUG
|
||||
var debugTexture = new Texture2D(GraphicsDevice, 1, 1);
|
||||
debugTexture.SetData(new Color[] { Color.White });
|
||||
foreach (var collisionComponent in EntityManager.GetComponents<Component.Collision>())
|
||||
{
|
||||
spriteBatch.Draw(debugTexture, collisionComponent.Rectangle, Color.Red * 0.5f);
|
||||
}
|
||||
#endif*/
|
||||
|
||||
// Draw mouse input visuals
|
||||
MouseInput.Draw(spriteBatch);
|
||||
|
||||
spriteBatch.End();
|
||||
GraphicsDevice.SetRenderTarget(null);
|
||||
|
||||
// Draw the scene from the render target with the light shader
|
||||
lightShader.Parameters["LightsTexture"].SetValue(lightRenderTarget);
|
||||
lightShader.CurrentTechnique.Passes[0].Apply();
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, null, null, lightShader,
|
||||
Matrix.Identity);
|
||||
spriteBatch.Draw(sceneRenderTarget, Vector2.Zero, Color.White);
|
||||
spriteBatch.End();
|
||||
|
||||
// Draw GUI components
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, null, null, null, Matrix.Identity);
|
||||
GUIManager.Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+197
-181
@@ -1,181 +1,197 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
public class MapTile
|
||||
{
|
||||
public int LocalId;
|
||||
public Texture2D Texture;
|
||||
public Rectangle SourceRectangle;
|
||||
public SpriteEffects SpriteEffects;
|
||||
}
|
||||
|
||||
public enum MapObjectType : byte
|
||||
{
|
||||
Plain,
|
||||
Tile,
|
||||
Polygon,
|
||||
Polyline
|
||||
}
|
||||
|
||||
public class MapObject
|
||||
{
|
||||
//public MapObjectType ObjectType;
|
||||
public string Name;
|
||||
public string Type;
|
||||
public Rectangle Bounds;
|
||||
public List<Vector2> Points;
|
||||
}
|
||||
|
||||
public class MapLayer
|
||||
{
|
||||
public int Width;
|
||||
public int Height;
|
||||
public string Name;
|
||||
}
|
||||
|
||||
public class MapTileLayer : MapLayer
|
||||
{
|
||||
public MapTile[] Tiles;
|
||||
}
|
||||
|
||||
public class MapObjectLayer : MapLayer
|
||||
{
|
||||
public MapObject[] Objects;
|
||||
}
|
||||
|
||||
public class Map
|
||||
{
|
||||
public int TileWidth;
|
||||
public int TileHeight;
|
||||
public List<MapLayer> Layers = new List<MapLayer>();
|
||||
|
||||
public Map()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ParseObjects(Core core)
|
||||
{
|
||||
foreach (var layer in Layers)
|
||||
{
|
||||
var objectLayer = layer as MapObjectLayer;
|
||||
|
||||
if (objectLayer == null)
|
||||
continue;
|
||||
|
||||
foreach (var mapObject in objectLayer.Objects)
|
||||
{
|
||||
if (mapObject.Type == "SquadStart")
|
||||
{
|
||||
var soldier = new Soldier(ref core.Squad);
|
||||
soldier.Name = "Derp";
|
||||
// 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);
|
||||
soldier.X = mapObjectGridPos.X;
|
||||
soldier.Y = mapObjectGridPos.Y;
|
||||
|
||||
core.Squad.Add(soldier);
|
||||
}
|
||||
if (mapObject.Type == "MonsterSpawn")
|
||||
{
|
||||
var enemy = new MonsterSpawn("Monster", ref core.Swarm);
|
||||
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
|
||||
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
||||
enemy.X = mapObjectGridPos.X;
|
||||
enemy.Y = mapObjectGridPos.Y;
|
||||
}
|
||||
if (mapObject.Type == "BossSpawn")
|
||||
{
|
||||
var enemy = new MonsterSpawn("BUB", ref core.Swarm);
|
||||
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
|
||||
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
||||
enemy.X = mapObjectGridPos.X;
|
||||
enemy.Y = mapObjectGridPos.Y;
|
||||
}
|
||||
if (mapObject.Type == "Door")
|
||||
{
|
||||
var door = new Door();
|
||||
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y);
|
||||
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
||||
door.X = mapObjectGridPos.X;
|
||||
door.Y = mapObjectGridPos.Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
foreach (var layer in Layers)
|
||||
{
|
||||
var tileLayer = layer as MapTileLayer;
|
||||
|
||||
if (tileLayer == null)
|
||||
continue;
|
||||
|
||||
// Don't draw the collision layer
|
||||
if (tileLayer.Name == "Collision")
|
||||
continue;
|
||||
|
||||
for (int y = 0; y < tileLayer.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < tileLayer.Width; x++)
|
||||
{
|
||||
MapTile mapTile = tileLayer.Tiles[y * layer.Width + x];
|
||||
if (mapTile != null)
|
||||
{
|
||||
spriteBatch.Draw(
|
||||
mapTile.Texture,
|
||||
new Rectangle(x * TileWidth, y * TileHeight, TileWidth, TileHeight),
|
||||
mapTile.SourceRectangle,
|
||||
Color.White,
|
||||
0,
|
||||
Vector2.Zero,
|
||||
mapTile.SpriteEffects,
|
||||
0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte[,] GetCollisionMap()
|
||||
{
|
||||
byte[,] collisionMap = null;
|
||||
|
||||
foreach (var layer in Layers)
|
||||
{
|
||||
var tileLayer = layer as MapTileLayer;
|
||||
|
||||
if (tileLayer != null && tileLayer.Name == "Collision")
|
||||
{
|
||||
collisionMap = new byte[1024,1024];
|
||||
for (int y = 0; y < tileLayer.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < tileLayer.Width; x++)
|
||||
{
|
||||
MapTile tile = tileLayer.Tiles[y * layer.Width + x];
|
||||
if (tile == null || tile.LocalId == 0)
|
||||
collisionMap[x, y] = 1;
|
||||
else
|
||||
collisionMap[x, y] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (collisionMap == null)
|
||||
Debug.WriteLine("Map lacks a Collision layer! Pathfinding won't work.");
|
||||
|
||||
return collisionMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
public class MapTile
|
||||
{
|
||||
public int LocalId;
|
||||
public Texture2D Texture;
|
||||
public Rectangle SourceRectangle;
|
||||
public SpriteEffects SpriteEffects;
|
||||
}
|
||||
|
||||
public enum MapObjectType : byte
|
||||
{
|
||||
Plain,
|
||||
Tile,
|
||||
Polygon,
|
||||
Polyline
|
||||
}
|
||||
|
||||
public class MapObject
|
||||
{
|
||||
//public MapObjectType ObjectType;
|
||||
public string Name;
|
||||
public string Type;
|
||||
public Rectangle Bounds;
|
||||
public List<Vector2> Points;
|
||||
}
|
||||
|
||||
public class MapLayer
|
||||
{
|
||||
public int Width;
|
||||
public int Height;
|
||||
public string Name;
|
||||
}
|
||||
|
||||
public class MapTileLayer : MapLayer
|
||||
{
|
||||
public MapTile[] Tiles;
|
||||
}
|
||||
|
||||
public class MapObjectLayer : MapLayer
|
||||
{
|
||||
public MapObject[] Objects;
|
||||
}
|
||||
|
||||
public class Map
|
||||
{
|
||||
public int TileWidth;
|
||||
public int TileHeight;
|
||||
public List<MapLayer> Layers = new List<MapLayer>();
|
||||
|
||||
public Map()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ParseObjects(Core core)
|
||||
{
|
||||
foreach (var layer in Layers)
|
||||
{
|
||||
var objectLayer = layer as MapObjectLayer;
|
||||
|
||||
if (objectLayer == null)
|
||||
continue;
|
||||
|
||||
foreach (var mapObject in objectLayer.Objects)
|
||||
{
|
||||
if (mapObject.Type == "SquadStart")
|
||||
{
|
||||
var soldier = new Soldier(ref core.Squad);
|
||||
soldier.Name = "Derp";
|
||||
// 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);
|
||||
soldier.X = mapObjectGridPos.X;
|
||||
soldier.Y = mapObjectGridPos.Y;
|
||||
|
||||
core.Squad.Add(soldier);
|
||||
}
|
||||
if (mapObject.Type == "MonsterSpawn" || mapObject.Type == "EnemySpawn")
|
||||
{
|
||||
var enemy = new MonsterSpawn("Monster", 14, 0, ref core.Swarm);
|
||||
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
|
||||
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
||||
enemy.X = mapObjectGridPos.X;
|
||||
enemy.Y = mapObjectGridPos.Y;
|
||||
}
|
||||
if (mapObject.Type == "AmbushMonsterSpawn" || mapObject.Type == "AmbushEnemySpawn")
|
||||
{
|
||||
var enemy = new MonsterSpawn("Monster", 2, 0, ref core.Swarm);
|
||||
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
|
||||
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
||||
enemy.X = mapObjectGridPos.X;
|
||||
enemy.Y = mapObjectGridPos.Y;
|
||||
}
|
||||
if (mapObject.Type == "DelayedMonsterSpawn" || mapObject.Type == "DelayedEnemySpawn")
|
||||
{
|
||||
var enemy = new MonsterSpawn("Monster", 200, 8, ref core.Swarm);
|
||||
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
|
||||
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
||||
enemy.X = mapObjectGridPos.X;
|
||||
enemy.Y = mapObjectGridPos.Y;
|
||||
}
|
||||
/*if (mapObject.Type == "BossSpawn")
|
||||
{
|
||||
var enemy = new MonsterSpawn("BUB", 12, 0, ref core.Swarm);
|
||||
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
|
||||
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
||||
enemy.X = mapObjectGridPos.X;
|
||||
enemy.Y = mapObjectGridPos.Y;
|
||||
}*/
|
||||
if (mapObject.Type == "Door")
|
||||
{
|
||||
var door = new Door();
|
||||
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y);
|
||||
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
||||
door.X = mapObjectGridPos.X;
|
||||
door.Y = mapObjectGridPos.Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
foreach (var layer in Layers)
|
||||
{
|
||||
var tileLayer = layer as MapTileLayer;
|
||||
|
||||
if (tileLayer == null)
|
||||
continue;
|
||||
|
||||
// Don't draw the collision layer
|
||||
if (tileLayer.Name == "Collision")
|
||||
continue;
|
||||
|
||||
for (int y = 0; y < tileLayer.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < tileLayer.Width; x++)
|
||||
{
|
||||
MapTile mapTile = tileLayer.Tiles[y * layer.Width + x];
|
||||
if (mapTile != null)
|
||||
{
|
||||
spriteBatch.Draw(
|
||||
mapTile.Texture,
|
||||
new Rectangle(x * TileWidth, y * TileHeight, TileWidth, TileHeight),
|
||||
mapTile.SourceRectangle,
|
||||
Color.White,
|
||||
0,
|
||||
Vector2.Zero,
|
||||
mapTile.SpriteEffects,
|
||||
0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte[,] GetCollisionMap()
|
||||
{
|
||||
byte[,] collisionMap = null;
|
||||
|
||||
foreach (var layer in Layers)
|
||||
{
|
||||
var tileLayer = layer as MapTileLayer;
|
||||
|
||||
if (tileLayer != null && tileLayer.Name == "Collision")
|
||||
{
|
||||
collisionMap = new byte[1024,1024];
|
||||
for (int y = 0; y < tileLayer.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < tileLayer.Width; x++)
|
||||
{
|
||||
MapTile tile = tileLayer.Tiles[y * layer.Width + x];
|
||||
if (tile == null || tile.LocalId == 0)
|
||||
collisionMap[x, y] = 1;
|
||||
else
|
||||
collisionMap[x, y] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (collisionMap == null)
|
||||
Debug.WriteLine("Map lacks a Collision layer! Pathfinding won't work.");
|
||||
|
||||
return collisionMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
public class MonsterSpawn : Entity
|
||||
{
|
||||
//EntityManager entityManager;
|
||||
|
||||
int wakingDistance = 7;
|
||||
int sleepingDistance = 6;
|
||||
|
||||
string type;
|
||||
|
||||
List<SmallEnemy> swarm;
|
||||
|
||||
public MonsterSpawn(string _type, ref List<SmallEnemy> Swarm)
|
||||
: base()
|
||||
{
|
||||
//this.entityManager = entityManager;
|
||||
type = _type;
|
||||
swarm = Swarm;
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
for (int index = 0; index < EntityManager.Entities.Count; index++)
|
||||
{
|
||||
var entity = EntityManager.Entities[index];
|
||||
if (entity is Soldier)
|
||||
{
|
||||
Vector2 distance1 = new Vector2(this.GetComponent<Component.Transform>().Grid.Position.X,
|
||||
this.GetComponent<Component.Transform>().Grid.Position.Y);
|
||||
Vector2 distance2 = new Vector2(entity.GetComponent<Component.Transform>().Grid.Position.X,
|
||||
entity.GetComponent<Component.Transform>().Grid.Position.Y);
|
||||
if (Vector2.Distance(distance1, distance2) < wakingDistance/* && Vector2.Distance(distance1, distance2) > sleepingDistance*/)
|
||||
{
|
||||
var enemy = new SmallEnemy(ref swarm);
|
||||
if (type == "BUB")
|
||||
{
|
||||
enemy.LoadBoss();
|
||||
}
|
||||
enemy.X = this.X;
|
||||
enemy.Y = this.Y;
|
||||
swarm.Add(enemy);
|
||||
this.Remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
public class MonsterSpawn : Entity
|
||||
{
|
||||
//EntityManager entityManager;
|
||||
|
||||
int wakingDistance = 12;
|
||||
int sleepingDistance = 6;
|
||||
int wakingTurn = 0;
|
||||
|
||||
string type;
|
||||
|
||||
List<SmallEnemy> swarm;
|
||||
|
||||
public MonsterSpawn(string _type, int _wakingDistance, int _wakingTurn, ref List<SmallEnemy> Swarm)
|
||||
: base()
|
||||
{
|
||||
//this.entityManager = entityManager;
|
||||
type = _type;
|
||||
swarm = Swarm;
|
||||
wakingDistance = _wakingDistance;
|
||||
wakingTurn = _wakingTurn;
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
for (int index = 0; index < EntityManager.Entities.Count; index++)
|
||||
{
|
||||
var entity = EntityManager.Entities[index];
|
||||
if (entity is Soldier)
|
||||
{
|
||||
Vector2 distance1 = new Vector2(this.GetComponent<Component.Transform>().Grid.Position.X,
|
||||
this.GetComponent<Component.Transform>().Grid.Position.Y);
|
||||
Vector2 distance2 = new Vector2(entity.GetComponent<Component.Transform>().Grid.Position.X,
|
||||
entity.GetComponent<Component.Transform>().Grid.Position.Y);
|
||||
if (Vector2.Distance(distance1, distance2) < wakingDistance && TurnManager.currentTurn >= wakingTurn/* && Vector2.Distance(distance1, distance2) > sleepingDistance*/)
|
||||
{
|
||||
var enemy = new SmallEnemy(ref swarm);
|
||||
if (type == "BUB")
|
||||
{
|
||||
enemy.LoadBoss();
|
||||
}
|
||||
enemy.X = this.X;
|
||||
enemy.Y = this.Y;
|
||||
swarm.Add(enemy);
|
||||
this.Remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,192 +1,192 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DepthsBelow.Component;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
public class SmallEnemy : Entity
|
||||
{
|
||||
public static Texture2D Texture;
|
||||
public Color Color;
|
||||
public static Point Origin;
|
||||
private bool _selected; //I guess as in "currently doing something"
|
||||
|
||||
public List<SmallEnemy> Swarm;
|
||||
|
||||
private PathFinder.Node nextNode;
|
||||
|
||||
public int numberOfSteps = 5;
|
||||
public int currentStep = 0;
|
||||
|
||||
public bool AttackedThisTurn = false;
|
||||
|
||||
public int step
|
||||
{
|
||||
get { return currentStep; }
|
||||
set
|
||||
{
|
||||
currentStep = value;
|
||||
}
|
||||
}
|
||||
|
||||
public SmallEnemy(ref List<SmallEnemy> swarm)
|
||||
: base()
|
||||
{
|
||||
if (Texture == null)
|
||||
LoadContent();
|
||||
|
||||
this.Swarm = swarm;
|
||||
|
||||
Transform.World.Origin = new Vector2(20, 16);
|
||||
|
||||
this.Color = Color.White;
|
||||
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
|
||||
AddComponent(rc);
|
||||
|
||||
var cc = new Collision(this, 32, 32);
|
||||
cc.Solid = true;
|
||||
AddComponent(cc);
|
||||
|
||||
var pfc = new PathFinder(this);
|
||||
AddComponent(pfc);
|
||||
|
||||
var stat = new Component.Stat(this)
|
||||
{
|
||||
Life = 50,
|
||||
Defence = 25,
|
||||
Strength = 26,
|
||||
GetAim = 100,
|
||||
GetDodge = 50
|
||||
};
|
||||
AddComponent(stat);
|
||||
}
|
||||
public override void Remove()
|
||||
{
|
||||
Swarm.Remove(this);
|
||||
|
||||
base.Remove();
|
||||
}
|
||||
|
||||
public bool Selected
|
||||
{
|
||||
get { return _selected; }
|
||||
set
|
||||
{
|
||||
_selected = value;
|
||||
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadContent()
|
||||
{
|
||||
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Monster");
|
||||
}
|
||||
|
||||
public void LoadBoss()
|
||||
{
|
||||
GetComponent<SpriteRenderer>().AlternativeTexture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Pineapple");
|
||||
var stat = new Component.Stat(this)
|
||||
{
|
||||
Life = 500,
|
||||
Defence = 15,
|
||||
Strength = 70,
|
||||
GetAim = 80,
|
||||
GetDodge = 5
|
||||
};
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
base.Update(gameTime);
|
||||
|
||||
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
|
||||
|
||||
if (nextNode == null)
|
||||
nextNode = GetComponent<PathFinder>().Next();
|
||||
|
||||
if (nextNode != null)
|
||||
{
|
||||
List<Point> soldierCollisions = new List<Point>();
|
||||
|
||||
// Collision with moving units
|
||||
foreach (var body in Swarm)
|
||||
{
|
||||
if (body != this)
|
||||
{
|
||||
if (body.Transform.Grid == nextNode.Position)
|
||||
{
|
||||
soldierCollisions.Add(body.Transform.Grid);
|
||||
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
|
||||
nextNode = GetComponent<PathFinder>().Next();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nextNode != null)
|
||||
{
|
||||
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
|
||||
// HACK: Make this work properly with other speeds...
|
||||
float speed = 4f;
|
||||
if (Transform.World.X < nodeWorldPos.X)
|
||||
{
|
||||
Transform.World.X += speed;
|
||||
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(0);
|
||||
}
|
||||
if (Transform.World.X > nodeWorldPos.X)
|
||||
{
|
||||
Transform.World.X -= speed;
|
||||
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(180);
|
||||
}
|
||||
if (Transform.World.Y < nodeWorldPos.Y)
|
||||
{
|
||||
Transform.World.Y += speed;
|
||||
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(90);
|
||||
}
|
||||
if (Transform.World.Y > nodeWorldPos.Y)
|
||||
{
|
||||
Transform.World.Y -= speed;
|
||||
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(270);
|
||||
}
|
||||
if (Transform.World == nodeWorldPos)
|
||||
{
|
||||
if (currentStep < numberOfSteps)
|
||||
{
|
||||
currentStep++;
|
||||
//lastLastNode = lastNode;
|
||||
//lastNode = nextNode;
|
||||
nextNode = GetComponent<PathFinder>().Next();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
GetComponent<PathFinder>().Stop();
|
||||
}
|
||||
foreach (var entity in EntityManager.Entities)
|
||||
{
|
||||
if (entity is Soldier)
|
||||
{
|
||||
if (entity.GetComponent<Component.Collision>().Rectangle.Intersects(this.GetComponent<Component.Collision>().Rectangle))
|
||||
{
|
||||
if (AttackedThisTurn == false)
|
||||
{
|
||||
if (Utility.AttackTest(this.GetComponent<Component.Stat>(), entity, Utility.CalculateHitChance(this.GetComponent<Component.Stat>(), this.Transform.World.Position, entity)))
|
||||
{
|
||||
AttackedThisTurn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DepthsBelow.Component;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
public class SmallEnemy : Entity
|
||||
{
|
||||
public static Texture2D Texture;
|
||||
public Color Color;
|
||||
public static Point Origin;
|
||||
private bool _selected; //I guess as in "currently doing something"
|
||||
|
||||
public List<SmallEnemy> Swarm;
|
||||
|
||||
private PathFinder.Node nextNode;
|
||||
|
||||
public int numberOfSteps = 8;
|
||||
public int currentStep = 0;
|
||||
|
||||
public bool AttackedThisTurn = false;
|
||||
|
||||
public int step
|
||||
{
|
||||
get { return currentStep; }
|
||||
set
|
||||
{
|
||||
currentStep = value;
|
||||
}
|
||||
}
|
||||
|
||||
public SmallEnemy(ref List<SmallEnemy> swarm)
|
||||
: base()
|
||||
{
|
||||
if (Texture == null)
|
||||
LoadContent();
|
||||
|
||||
this.Swarm = swarm;
|
||||
|
||||
Transform.World.Origin = new Vector2(20, 16);
|
||||
|
||||
this.Color = Color.White;
|
||||
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
|
||||
AddComponent(rc);
|
||||
|
||||
var cc = new Collision(this, 32, 32);
|
||||
cc.Solid = true;
|
||||
AddComponent(cc);
|
||||
|
||||
var pfc = new PathFinder(this);
|
||||
AddComponent(pfc);
|
||||
|
||||
var stat = new Component.Stat(this)
|
||||
{
|
||||
Life = 50,
|
||||
Defence = 25,
|
||||
Strength = 70,
|
||||
GetAim = 100,
|
||||
GetDodge = 50
|
||||
};
|
||||
AddComponent(stat);
|
||||
}
|
||||
public override void Remove()
|
||||
{
|
||||
Swarm.Remove(this);
|
||||
|
||||
base.Remove();
|
||||
}
|
||||
|
||||
public bool Selected
|
||||
{
|
||||
get { return _selected; }
|
||||
set
|
||||
{
|
||||
_selected = value;
|
||||
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadContent()
|
||||
{
|
||||
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Monster");
|
||||
}
|
||||
|
||||
public void LoadBoss()
|
||||
{
|
||||
GetComponent<SpriteRenderer>().AlternativeTexture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Pineapple");
|
||||
var stat = new Component.Stat(this)
|
||||
{
|
||||
Life = 500,
|
||||
Defence = 15,
|
||||
Strength = 70,
|
||||
GetAim = 80,
|
||||
GetDodge = 5
|
||||
};
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
base.Update(gameTime);
|
||||
|
||||
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
|
||||
|
||||
if (nextNode == null)
|
||||
nextNode = GetComponent<PathFinder>().Next();
|
||||
|
||||
if (nextNode != null)
|
||||
{
|
||||
List<Point> soldierCollisions = new List<Point>();
|
||||
|
||||
// Collision with moving units
|
||||
foreach (var body in Swarm)
|
||||
{
|
||||
if (body != this)
|
||||
{
|
||||
if (body.Transform.Grid == nextNode.Position)
|
||||
{
|
||||
soldierCollisions.Add(body.Transform.Grid);
|
||||
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
|
||||
nextNode = GetComponent<PathFinder>().Next();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nextNode != null)
|
||||
{
|
||||
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
|
||||
// HACK: Make this work properly with other speeds...
|
||||
float speed = 4f;
|
||||
if (Transform.World.X < nodeWorldPos.X)
|
||||
{
|
||||
Transform.World.X += speed;
|
||||
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(0);
|
||||
}
|
||||
if (Transform.World.X > nodeWorldPos.X)
|
||||
{
|
||||
Transform.World.X -= speed;
|
||||
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(180);
|
||||
}
|
||||
if (Transform.World.Y < nodeWorldPos.Y)
|
||||
{
|
||||
Transform.World.Y += speed;
|
||||
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(90);
|
||||
}
|
||||
if (Transform.World.Y > nodeWorldPos.Y)
|
||||
{
|
||||
Transform.World.Y -= speed;
|
||||
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(270);
|
||||
}
|
||||
if (Transform.World == nodeWorldPos)
|
||||
{
|
||||
if (currentStep < numberOfSteps)
|
||||
{
|
||||
currentStep++;
|
||||
//lastLastNode = lastNode;
|
||||
//lastNode = nextNode;
|
||||
nextNode = GetComponent<PathFinder>().Next();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
GetComponent<PathFinder>().Stop();
|
||||
}
|
||||
foreach (var entity in EntityManager.Entities)
|
||||
{
|
||||
if (entity is Soldier)
|
||||
{
|
||||
if (entity.GetComponent<Component.Collision>().Rectangle.Intersects(this.GetComponent<Component.Collision>().Rectangle))
|
||||
{
|
||||
if (AttackedThisTurn == false)
|
||||
{
|
||||
if (Utility.AttackTest(this.GetComponent<Component.Stat>(), entity, Utility.CalculateHitChance(this.GetComponent<Component.Stat>(), this.Transform.World.Position, entity)))
|
||||
{
|
||||
AttackedThisTurn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,115 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
/// <summary>
|
||||
/// Keeps track of whose turn it is.
|
||||
/// </summary>
|
||||
public class TurnManager
|
||||
{
|
||||
/// <summary>
|
||||
/// A player turn token.
|
||||
/// </summary>
|
||||
public class Token
|
||||
{
|
||||
/// <summary>
|
||||
/// Unique identifying name of the token.
|
||||
/// </summary>
|
||||
public string Name { get; private set; }
|
||||
private TurnManager turnManager;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Token" /> class.
|
||||
/// Preferably use <see cref="TurnManager.CreateToken" /> instead.
|
||||
/// </summary>
|
||||
/// <param name="turnManager">The turn manager the token belongs to.</param>
|
||||
/// <param name="name">Unique identifying name of the token.</param>
|
||||
public Token(TurnManager turnManager, string name)
|
||||
{
|
||||
this.turnManager = turnManager;
|
||||
this.Name = name;
|
||||
turnManager.AddToken(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary of turn tokens.
|
||||
/// </summary>
|
||||
public Dictionary<string, Token> Tokens;
|
||||
private int currentTokenIndex;
|
||||
|
||||
/// <summary>
|
||||
/// The turn token belonging to a player.
|
||||
/// </summary>
|
||||
public Token CurrentTurn
|
||||
{
|
||||
get { return Tokens.ElementAt(currentTokenIndex).Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the turn token by the specified name.
|
||||
/// </summary>
|
||||
/// <param name="name">The identifying name of the player.</param>
|
||||
/// <returns>Returns a player turn token.</returns>
|
||||
public Token this[string name]
|
||||
{
|
||||
get { return this.Tokens[name]; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a turn manager.
|
||||
/// </summary>
|
||||
public TurnManager()
|
||||
{
|
||||
Tokens = new Dictionary<string, Token>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a turn manager.
|
||||
/// </summary>
|
||||
/// <param name="tokenNames">Tokens of players.</param>
|
||||
public TurnManager(string[] tokenNames)
|
||||
: this()
|
||||
{
|
||||
foreach (var tokenName in tokenNames)
|
||||
CreateToken(tokenName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a turn token.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the token.</param>
|
||||
/// <returns>Returns a player turn token.</returns>
|
||||
public Token CreateToken(string name)
|
||||
{
|
||||
return Tokens.ContainsKey(name) ? Tokens[name] : new Token(this, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a turn token to
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
public void AddToken(Token token)
|
||||
{
|
||||
if (!Tokens.ContainsKey(token.Name))
|
||||
Tokens.Add(token.Name, token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// End the current turn, skipping to the next token in the dictionary.
|
||||
/// </summary>
|
||||
public void EndTurn()
|
||||
{
|
||||
var prevTurn = CurrentTurn;
|
||||
|
||||
if (++currentTokenIndex > Tokens.Count - 1)
|
||||
currentTokenIndex = 0;
|
||||
|
||||
Debug.WriteLine(prevTurn.Name + " turn ended. Current turn: " + CurrentTurn.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DepthsBelow
|
||||
{
|
||||
/// <summary>
|
||||
/// Keeps track of whose turn it is.
|
||||
/// </summary>
|
||||
public class TurnManager
|
||||
{
|
||||
public static int currentTurn = 0;
|
||||
|
||||
/// <summary>
|
||||
/// A player turn token.
|
||||
/// </summary>
|
||||
public class Token
|
||||
{
|
||||
/// <summary>
|
||||
/// Unique identifying name of the token.
|
||||
/// </summary>
|
||||
public string Name { get; private set; }
|
||||
private TurnManager turnManager;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Token" /> class.
|
||||
/// Preferably use <see cref="TurnManager.CreateToken" /> instead.
|
||||
/// </summary>
|
||||
/// <param name="turnManager">The turn manager the token belongs to.</param>
|
||||
/// <param name="name">Unique identifying name of the token.</param>
|
||||
public Token(TurnManager turnManager, string name)
|
||||
{
|
||||
this.turnManager = turnManager;
|
||||
this.Name = name;
|
||||
turnManager.AddToken(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary of turn tokens.
|
||||
/// </summary>
|
||||
public Dictionary<string, Token> Tokens;
|
||||
private int currentTokenIndex;
|
||||
|
||||
/// <summary>
|
||||
/// The turn token belonging to a player.
|
||||
/// </summary>
|
||||
public Token CurrentTurn
|
||||
{
|
||||
get { return Tokens.ElementAt(currentTokenIndex).Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the turn token by the specified name.
|
||||
/// </summary>
|
||||
/// <param name="name">The identifying name of the player.</param>
|
||||
/// <returns>Returns a player turn token.</returns>
|
||||
public Token this[string name]
|
||||
{
|
||||
get { return this.Tokens[name]; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a turn manager.
|
||||
/// </summary>
|
||||
public TurnManager()
|
||||
{
|
||||
Tokens = new Dictionary<string, Token>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a turn manager.
|
||||
/// </summary>
|
||||
/// <param name="tokenNames">Tokens of players.</param>
|
||||
public TurnManager(string[] tokenNames)
|
||||
: this()
|
||||
{
|
||||
foreach (var tokenName in tokenNames)
|
||||
CreateToken(tokenName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a turn token.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the token.</param>
|
||||
/// <returns>Returns a player turn token.</returns>
|
||||
public Token CreateToken(string name)
|
||||
{
|
||||
return Tokens.ContainsKey(name) ? Tokens[name] : new Token(this, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a turn token to
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
public void AddToken(Token token)
|
||||
{
|
||||
if (!Tokens.ContainsKey(token.Name))
|
||||
Tokens.Add(token.Name, token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// End the current turn, skipping to the next token in the dictionary.
|
||||
/// </summary>
|
||||
public void EndTurn()
|
||||
{
|
||||
var prevTurn = CurrentTurn;
|
||||
|
||||
if (++currentTokenIndex > Tokens.Count - 1)
|
||||
currentTokenIndex = 0;
|
||||
|
||||
Debug.WriteLine(prevTurn.Name + " turn ended. Current turn: " + CurrentTurn.Name);
|
||||
if (CurrentTurn.Name == "Player")
|
||||
{
|
||||
currentTurn++;
|
||||
Console.WriteLine("Turn: " + currentTurn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<object type="SquadStart" x="768" y="2720" width="32" height="32"/>
|
||||
<object type="BossSpawn" x="832" y="2720" width="32" height="32"/>
|
||||
<object type="Door" x="640" y="2656" width="32" height="64"/>
|
||||
<object type="EnemySpawn" x="992" y="2304" width="32" height="32"/>
|
||||
<object type="MonsterSpawn" x="992" y="2304" width="32" height="32"/>
|
||||
<object type="EnemySpawn" x="1184" y="2144" width="32" height="32"/>
|
||||
<object type="EnemySpawn" x="992" y="2688" width="32" height="32"/>
|
||||
<object type="EnemySpawn" x="1088" y="2560" width="32" height="32"/>
|
||||
@@ -59,6 +59,14 @@
|
||||
<object type="EnemySpawn" x="3424" y="800" width="32" height="32"/>
|
||||
<object type="EnemySpawn" x="3424" y="640" width="32" height="32"/>
|
||||
<object type="EnemySpawn" x="2112" y="640" width="32" height="32"/>
|
||||
|
||||
<object type="DelayedEnemySpawn" x="704" y="2624" width="32" height="32"/>
|
||||
<object type="DelayedEnemySpawn" x="736" y="2656" width="32" height="32"/>
|
||||
<object type="DelayedEnemySpawn" x="704" y="2720" width="32" height="32"/>
|
||||
<object type="DelayedEnemySpawn" x="800" y="2656" width="32" height="32"/>
|
||||
<object type="DelayedEnemySpawn" x="768" y="2720" width="32" height="32"/>
|
||||
<object type="DelayedEnemySpawn" x="832" y="2720" width="32" height="32"/>
|
||||
|
||||
</objectgroup>
|
||||
<layer name="Collision" width="256" height="256">
|
||||
<data encoding="base64" compression="zlib">
|
||||
|
||||
Reference in New Issue
Block a user