The hell. Vi kan skjuta med S.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
namespace DepthsBelow.Component
|
namespace DepthsBelow.Component
|
||||||
{
|
{
|
||||||
@@ -39,7 +40,15 @@ namespace DepthsBelow.Component
|
|||||||
protected int ammo = 0;
|
protected int ammo = 0;
|
||||||
protected int enemyDodge = 0;
|
protected int enemyDodge = 0;
|
||||||
|
|
||||||
protected int penaltyRange = 5;
|
protected int penaltyRange = 5;
|
||||||
|
|
||||||
|
Vector2 rememberedPosition = Vector2.Zero;
|
||||||
|
|
||||||
|
public Vector2 Remember
|
||||||
|
{
|
||||||
|
get { return rememberedPosition; }
|
||||||
|
set { rememberedPosition = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public int GetAim
|
public int GetAim
|
||||||
{
|
{
|
||||||
@@ -83,7 +92,8 @@ namespace DepthsBelow.Component
|
|||||||
|
|
||||||
public void Kill()
|
public void Kill()
|
||||||
{
|
{
|
||||||
hp = 0;
|
hp = 0;
|
||||||
|
Parent.Remove();
|
||||||
//Console.WriteLine("Blargh! I am dead!");
|
//Console.WriteLine("Blargh! I am dead!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +104,8 @@ namespace DepthsBelow.Component
|
|||||||
|
|
||||||
public Stat(Entity parent)
|
public Stat(Entity parent)
|
||||||
: base (parent)
|
: base (parent)
|
||||||
{
|
{
|
||||||
|
rememberedPosition = Vector2.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool targetInSight()
|
public bool targetInSight()
|
||||||
|
|||||||
+250
-250
@@ -1,250 +1,250 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using DepthsBelow.GUI;
|
using DepthsBelow.GUI;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Audio;
|
using Microsoft.Xna.Framework.Audio;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.GamerServices;
|
using Microsoft.Xna.Framework.GamerServices;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using Microsoft.Xna.Framework.Media;
|
using Microsoft.Xna.Framework.Media;
|
||||||
|
|
||||||
namespace DepthsBelow
|
namespace DepthsBelow
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the main type for your game
|
/// This is the main type for your game
|
||||||
/// </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()
|
||||||
{
|
{
|
||||||
GraphicsDeviceManager = new GraphicsDeviceManager(this);
|
GraphicsDeviceManager = new GraphicsDeviceManager(this);
|
||||||
GraphicsDeviceManager.PreferredBackBufferWidth = 1280;
|
GraphicsDeviceManager.PreferredBackBufferWidth = 1280;
|
||||||
GraphicsDeviceManager.PreferredBackBufferHeight = 720;
|
GraphicsDeviceManager.PreferredBackBufferHeight = 720;
|
||||||
GraphicsDeviceManager.IsFullScreen = false;
|
GraphicsDeviceManager.IsFullScreen = false;
|
||||||
//graphics.SynchronizeWithVerticalRetrace = false;
|
//graphics.SynchronizeWithVerticalRetrace = false;
|
||||||
GraphicsDeviceManager.ApplyChanges();
|
GraphicsDeviceManager.ApplyChanges();
|
||||||
|
|
||||||
this.IsFixedTimeStep = false;
|
this.IsFixedTimeStep = false;
|
||||||
this.IsMouseVisible = true;
|
this.IsMouseVisible = true;
|
||||||
|
|
||||||
Content.RootDirectory = "Content";
|
Content.RootDirectory = "Content";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows the game to perform any initialization it needs to before starting to run.
|
/// 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
|
/// 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
|
/// related content. Calling base.Initialize will enumerate through any components
|
||||||
/// 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LoadContent will be called once per game and is the place to load
|
/// LoadContent will be called once per game and is the place to load
|
||||||
/// all of your content.
|
/// all of your content.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
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");
|
//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[0].Name = "Dean H. Jones";
|
||||||
Squad[1].Name = "Walter L. Verville";
|
Squad[1].Name = "Walter L. Verville";
|
||||||
Squad[2].Name = "Patrick Y. Southerland";
|
Squad[2].Name = "Patrick Y. Southerland";
|
||||||
Squad[3].Name = "Andrew C. Friend";
|
Squad[3].Name = "Andrew C. Friend";
|
||||||
Squad[4].Name = "Gary B. Whitley";
|
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
|
||||||
Soldier.LoadContent();
|
Soldier.LoadContent();
|
||||||
SmallEnemy.LoadContent();
|
SmallEnemy.LoadContent();
|
||||||
Shot.LoadContent();
|
//Shot.LoadContent();
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UnloadContent will be called once per game and is the place to unload
|
/// UnloadContent will be called once per game and is the place to unload
|
||||||
/// all content.
|
/// all content.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void UnloadContent()
|
protected override void UnloadContent()
|
||||||
{
|
{
|
||||||
// TODO: Unload any non ContentManager content here
|
// TODO: Unload any non ContentManager content here
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows the game to run logic such as updating the world,
|
/// Allows the game to run logic such as updating the world,
|
||||||
/// checking for collisions, gathering input, and playing audio.
|
/// checking for collisions, gathering input, and playing audio.
|
||||||
/// </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 Update(GameTime gameTime)
|
protected override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
// Allows the game to exit
|
// Allows the game to exit
|
||||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
||||||
this.Exit();
|
this.Exit();
|
||||||
|
|
||||||
Camera.Update(gameTime);
|
Camera.Update(gameTime);
|
||||||
MouseInput.Update(gameTime);
|
MouseInput.Update(gameTime);
|
||||||
KeyboardInput.Update(gameTime);
|
KeyboardInput.Update(gameTime);
|
||||||
|
|
||||||
EntityManager.Update(gameTime);
|
EntityManager.Update(gameTime);
|
||||||
|
|
||||||
Interface.Update(gameTime);
|
Interface.Update(gameTime);
|
||||||
GUIManager.Update(gameTime);
|
GUIManager.Update(gameTime);
|
||||||
|
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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,
|
||||||
Camera.Transform);
|
Camera.Transform);
|
||||||
|
|
||||||
// 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();
|
||||||
|
|
||||||
// Draw GUI components
|
// Draw GUI components
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, null, null, null, Matrix.Identity);
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, null, null, null, Matrix.Identity);
|
||||||
GUIManager.Draw(spriteBatch);
|
GUIManager.Draw(spriteBatch);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ namespace DepthsBelow
|
|||||||
{
|
{
|
||||||
if (soldier.Selected == true && soldier.Fired == false)
|
if (soldier.Selected == true && soldier.Fired == false)
|
||||||
{
|
{
|
||||||
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>()));
|
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), "Bullet"));
|
||||||
soldier.Fired = true;
|
soldier.Fired = true;
|
||||||
foreach (var shot in core.Volley)
|
foreach (var shot in core.Volley)
|
||||||
{
|
{
|
||||||
@@ -225,10 +225,12 @@ namespace DepthsBelow
|
|||||||
}
|
}
|
||||||
if (shot.direction == Vector2.Zero)
|
if (shot.direction == Vector2.Zero)
|
||||||
{
|
{
|
||||||
double directionX = Math.Cos(soldier.GetComponent<Component.Transform>().World.Rotation);
|
double directionX = Math.Cos(soldier.Transform.World.Rotation);
|
||||||
double directionY = Math.Sin(soldier.GetComponent<Component.Transform>().World.Rotation);
|
double directionY = Math.Sin(soldier.Transform.World.Rotation);
|
||||||
shot.direction = new Vector2((float)directionX, (float)directionY);
|
shot.direction = new Vector2((float)directionX, (float)directionY);
|
||||||
shot.Transform.World.Rotation = soldier.Transform.World.Rotation;
|
shot.Transform.World.Rotation = soldier.Transform.World.Rotation;
|
||||||
|
Vector2 yo = soldier.Transform.World.Position;
|
||||||
|
shot.Stat.Remember = yo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -268,7 +270,7 @@ namespace DepthsBelow
|
|||||||
current = 0;
|
current = 0;
|
||||||
if (soldier.Selected == true && soldier.Fired == false && hit == true)
|
if (soldier.Selected == true && soldier.Fired == false && hit == true)
|
||||||
{
|
{
|
||||||
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>()));
|
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), "Bullet"));
|
||||||
soldier.Fired = true;
|
soldier.Fired = true;
|
||||||
foreach (var shot in core.Volley)
|
foreach (var shot in core.Volley)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ namespace DepthsBelow
|
|||||||
{
|
{
|
||||||
if (gridRectangle.Intersects(enemy.GetComponent<Component.Collision>().Rectangle))
|
if (gridRectangle.Intersects(enemy.GetComponent<Component.Collision>().Rectangle))
|
||||||
{
|
{
|
||||||
Console.WriteLine(Utility.CalculateHitChance(unit, enemy));
|
Console.WriteLine(Utility.CalculateHitChance(unit.GetComponent<Component.Stat>(), unit.GetComponent<Component.Transform>().World.Position, enemy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace DepthsBelow
|
|||||||
public static Texture2D Texture;
|
public static Texture2D Texture;
|
||||||
public Color Color;
|
public Color Color;
|
||||||
public static Point Origin;
|
public static Point Origin;
|
||||||
|
string type = "";
|
||||||
|
|
||||||
Stat soldierStat;
|
Stat soldierStat;
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
public Vector2 direction = Vector2.Zero;
|
public Vector2 direction = Vector2.Zero;
|
||||||
|
|
||||||
public Shot(EntityManager entityManager, Stat _soldierStat)
|
public Shot(EntityManager entityManager, Stat _soldierStat, string _type)
|
||||||
: base(entityManager)
|
: base(entityManager)
|
||||||
{
|
{
|
||||||
if (Texture == null)
|
if (Texture == null)
|
||||||
@@ -46,6 +47,7 @@ namespace DepthsBelow
|
|||||||
Transform.World.Origin = new Vector2(16, 16);
|
Transform.World.Origin = new Vector2(16, 16);
|
||||||
|
|
||||||
Stat = _soldierStat;
|
Stat = _soldierStat;
|
||||||
|
type = _type;
|
||||||
|
|
||||||
this.Color = Color.White;
|
this.Color = Color.White;
|
||||||
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
|
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
|
||||||
@@ -55,9 +57,16 @@ namespace DepthsBelow
|
|||||||
AddComponent(cc);
|
AddComponent(cc);
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void LoadContent()
|
public void LoadContent()
|
||||||
{
|
{
|
||||||
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot");
|
if (type == "Rocket")
|
||||||
|
{
|
||||||
|
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot3");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
@@ -76,7 +85,11 @@ namespace DepthsBelow
|
|||||||
{
|
{
|
||||||
if (this.GetComponent<Component.Collision>().Rectangle.Intersects(entity.GetComponent<Component.Collision>().Rectangle))
|
if (this.GetComponent<Component.Collision>().Rectangle.Intersects(entity.GetComponent<Component.Collision>().Rectangle))
|
||||||
{
|
{
|
||||||
|
if (Utility.HitTest(Stat, entity, Utility.CalculateHitChance(Stat, this.Stat.Remember, entity)))
|
||||||
|
{
|
||||||
|
this.Remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,152 +1,164 @@
|
|||||||
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;
|
||||||
|
|
||||||
namespace DepthsBelow
|
namespace DepthsBelow
|
||||||
{
|
{
|
||||||
public class SmallEnemy : Entity
|
public class SmallEnemy : Entity
|
||||||
{
|
{
|
||||||
public static Texture2D Texture;
|
public static Texture2D Texture;
|
||||||
public Color Color;
|
public Color Color;
|
||||||
public static Point Origin;
|
public static Point Origin;
|
||||||
private bool _selected; //I guess as in "currently doing something"
|
private bool _selected; //I guess as in "currently doing something"
|
||||||
|
|
||||||
public List<SmallEnemy> Swarm;
|
public List<SmallEnemy> Swarm;
|
||||||
|
|
||||||
private PathFinder.Node nextNode;
|
private PathFinder.Node nextNode;
|
||||||
|
|
||||||
public int numberOfSteps = 5;
|
public int numberOfSteps = 5;
|
||||||
public int currentStep = 0;
|
public int currentStep = 0;
|
||||||
|
|
||||||
public int step
|
public int step
|
||||||
{
|
{
|
||||||
get { return currentStep; }
|
get { return currentStep; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
currentStep = value;
|
currentStep = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
LoadContent();
|
LoadContent();
|
||||||
|
|
||||||
this.Swarm = swarm;
|
this.Swarm = swarm;
|
||||||
|
|
||||||
Transform.World.Origin = new Vector2(20, 16);
|
Transform.World.Origin = new Vector2(20, 16);
|
||||||
|
|
||||||
this.Color = Color.White;
|
this.Color = Color.White;
|
||||||
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
|
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
|
||||||
AddComponent(rc);
|
AddComponent(rc);
|
||||||
|
|
||||||
var cc = new Collision(this, 32, 32);
|
var cc = new Collision(this, 32, 32);
|
||||||
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 = 2,
|
||||||
Strength = 5000,
|
Strength = 5000,
|
||||||
GetAim = 100,
|
GetAim = 100,
|
||||||
GetDodge = 50
|
GetDodge = 50
|
||||||
};
|
};
|
||||||
AddComponent(stat);
|
AddComponent(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Selected
|
public bool Selected
|
||||||
{
|
{
|
||||||
get { return _selected; }
|
get { return _selected; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_selected = value;
|
_selected = value;
|
||||||
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
|
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadContent()
|
public static void LoadContent()
|
||||||
{
|
{
|
||||||
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Monster");
|
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Monster");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
|
|
||||||
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
|
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
|
||||||
|
|
||||||
if (nextNode == null)
|
if (nextNode == null)
|
||||||
nextNode = GetComponent<PathFinder>().Next();
|
nextNode = GetComponent<PathFinder>().Next();
|
||||||
|
|
||||||
if (nextNode != null)
|
if (nextNode != null)
|
||||||
{
|
{
|
||||||
List<Point> soldierCollisions = new List<Point>();
|
List<Point> soldierCollisions = new List<Point>();
|
||||||
|
|
||||||
// Collision with moving units
|
// Collision with moving units
|
||||||
foreach (var body in Swarm)
|
foreach (var body in Swarm)
|
||||||
{
|
{
|
||||||
if (body != this)
|
if (body != this)
|
||||||
{
|
{
|
||||||
if (body.Transform.Grid == nextNode.Position)
|
if (body.Transform.Grid == nextNode.Position)
|
||||||
{
|
{
|
||||||
soldierCollisions.Add(body.Transform.Grid);
|
soldierCollisions.Add(body.Transform.Grid);
|
||||||
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
|
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
|
||||||
nextNode = GetComponent<PathFinder>().Next();
|
nextNode = GetComponent<PathFinder>().Next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextNode != null)
|
if (nextNode != null)
|
||||||
{
|
{
|
||||||
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
|
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
|
||||||
// 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);
|
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);
|
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);
|
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);
|
GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(270);
|
||||||
}
|
}
|
||||||
if (Transform.World == nodeWorldPos)
|
if (Transform.World == nodeWorldPos)
|
||||||
{
|
{
|
||||||
if (currentStep < numberOfSteps)
|
if (currentStep < numberOfSteps)
|
||||||
{
|
{
|
||||||
currentStep++;
|
currentStep++;
|
||||||
//lastLastNode = lastNode;
|
//lastLastNode = lastNode;
|
||||||
//lastNode = nextNode;
|
//lastNode = nextNode;
|
||||||
nextNode = GetComponent<PathFinder>().Next();
|
nextNode = GetComponent<PathFinder>().Next();
|
||||||
}
|
}
|
||||||
else
|
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 (Utility.HitTest(this.GetComponent<Component.Stat>(), entity, Utility.CalculateHitChance(this.GetComponent<Component.Stat>(), this.Transform.World.Position, entity)))
|
||||||
}
|
{
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GetComponent<PathFinder>().Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ namespace DepthsBelow
|
|||||||
MaxPanic = 100,
|
MaxPanic = 100,
|
||||||
//Life = 10,
|
//Life = 10,
|
||||||
Defence = 10,
|
Defence = 10,
|
||||||
Strength = 10,
|
Strength = 50,
|
||||||
GetAim = 40,
|
GetAim = 40,
|
||||||
GetDodge = 20
|
GetDodge = 20
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ namespace DepthsBelow
|
|||||||
/// <param name="attacker">The attacking unit.</param>
|
/// <param name="attacker">The attacking unit.</param>
|
||||||
/// <param name="defender">The recieving unit.</param>
|
/// <param name="defender">The recieving unit.</param>
|
||||||
/// <returns>Returns a hit chance percentage.</returns>
|
/// <returns>Returns a hit chance percentage.</returns>
|
||||||
public static int CalculateHitChance(Entity attacker, Entity defender)
|
public static int CalculateHitChance(Stat attacker, Vector2 attackerPosition, Entity defender)
|
||||||
{
|
{
|
||||||
Stat shooting = attacker.GetComponent<Stat>();
|
Stat shooting = attacker;
|
||||||
Stat dodging = defender.GetComponent<Stat>();
|
Stat dodging = defender.GetComponent<Stat>();
|
||||||
if (shooting == null || dodging == null)
|
if (shooting == null || dodging == null)
|
||||||
{
|
{
|
||||||
@@ -29,16 +29,16 @@ namespace DepthsBelow
|
|||||||
}
|
}
|
||||||
int baseHitChance = shooting.GetAim;
|
int baseHitChance = shooting.GetAim;
|
||||||
int baseDodgeChance = dodging.GetDodge;
|
int baseDodgeChance = dodging.GetDodge;
|
||||||
int distance = (int)Vector2.Distance(attacker.GetComponent<Transform>().World.Position, defender.GetComponent<Transform>().World.Position);
|
int distance = (int)Vector2.Distance(attackerPosition, defender.Transform.World.Position);
|
||||||
int basePenalty = shooting.Penalty(distance / (Grid.TileSize));
|
int basePenalty = shooting.Penalty(distance / (Grid.TileSize));
|
||||||
Console.WriteLine("Penalty = " + basePenalty);
|
Console.WriteLine("Penalty = " + basePenalty);
|
||||||
int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
|
int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
|
||||||
//Console.WriteLine(chanceToHit);
|
//Console.WriteLine(chanceToHit);
|
||||||
return chanceToHit;
|
return chanceToHit;
|
||||||
}
|
}
|
||||||
public static bool HitTest(Entity attacker, Entity defender, int chanceToHit)
|
public static bool HitTest(Stat attacker, Entity defender, int chanceToHit)
|
||||||
{
|
{
|
||||||
Component.Stat shooting = attacker.GetComponent<Component.Stat>();
|
Component.Stat shooting = attacker;
|
||||||
Component.Stat dodging = defender.GetComponent<Component.Stat>();
|
Component.Stat dodging = defender.GetComponent<Component.Stat>();
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
if (rand.Next(0, 100) < chanceToHit)
|
if (rand.Next(0, 100) < chanceToHit)
|
||||||
|
|||||||
@@ -231,6 +231,13 @@
|
|||||||
<Processor>TextureProcessor</Processor>
|
<Processor>TextureProcessor</Processor>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="images\Shot3.bmp">
|
||||||
|
<Name>Shot3</Name>
|
||||||
|
<Importer>TextureImporter</Importer>
|
||||||
|
<Processor>TextureProcessor</Processor>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 142 B |
Reference in New Issue
Block a user