Shooting calculation displayed, needs work

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-10-20 13:01:57 +02:00
parent 6034dbf3b2
commit 2fe63f51c0
5 changed files with 74 additions and 61 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ namespace DepthsBelow.Component
public int GetAim
{
get { return soldierAim + weaponAccuracy; }
set { soldierAim = value; }
set { weaponAccuracy = value; }
}
public int GetDodge
+17 -17
View File
@@ -12,7 +12,7 @@ namespace DepthsBelow
{
public class KeyboardInput
{
Core core;
Core core;
private KeyboardState lastKeyboardState;
int checkerSpeed = 2;
@@ -20,29 +20,29 @@ namespace DepthsBelow
public KeyboardInput(Core core)
{
this.core = core;
}
}
public void Update(GameTime gameTime)
{
KeyboardState ks = Keyboard.GetState();
// Lua reload scripts
if (ks.IsKeyUp(Keys.R) && lastKeyboardState.IsKeyDown(Keys.R))
{
core.Lua.Reload();
// Lua reload scripts
if (ks.IsKeyUp(Keys.R) && lastKeyboardState.IsKeyDown(Keys.R))
{
core.Lua.Reload();
}
// Next turn
if (ks.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter))
{
{
if (core.TurnManager.CurrentTurn == core.TurnManager["Player"])
{
foreach (var unit in core.Squad)
{
unit.step = 0;
unit.Fired = false;
}
}
core.TurnManager.EndTurn();
}
@@ -65,8 +65,8 @@ namespace DepthsBelow
}
}
core.TestMonster.GetComponent<Component.PathFinder>().Goal = target;
distance = 7000;
distance = 7000;
core.TurnManager.EndTurn();
}
}
@@ -86,7 +86,7 @@ namespace DepthsBelow
{
if (soldier.Selected == true && soldier.Fired == false)
{
core.Volley.Add(new Shot(core.EntityManager));
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>()));
soldier.Fired = true;
foreach (var shot in core.Volley)
{
@@ -143,7 +143,7 @@ namespace DepthsBelow
current = 0;
if (soldier.Selected == true && soldier.Fired == false && hit == true)
{
core.Volley.Add(new Shot(core.EntityManager));
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>()));
soldier.Fired = true;
foreach (var shot in core.Volley)
{
@@ -165,9 +165,9 @@ namespace DepthsBelow
hit = false;
}
}
}
lastKeyboardState = ks;
}
lastKeyboardState = ks;
}
}
}
+9 -8
View File
@@ -118,21 +118,22 @@ namespace DepthsBelow
readjust = false;
}
}
//Calculating chance to hit if holding cursor over enemy
foreach (var unit in core.Squad)
}
//Calculating chance to hit if holding cursor over enemy
foreach (var unit in core.Squad)
{
if (unit.Selected == true && unit.Fired == false)
{
if (unit.Selected == true && unit.Fired == false)
foreach (var enemy in core.Swarm)
{
foreach (var enemy in core.Swarm)
if (gridRectangle.Intersects(enemy.GetComponent<Component.Collision>().Rectangle))
{
if (gridRectangle.Intersects(enemy.GetComponent<Component.Collision>().Rectangle))
{
Utility.CalculateHitChance(unit, enemy);
}
Console.WriteLine(Utility.CalculateHitChance(unit, enemy));
}
}
}
}
// When the mouse is released
if (ms.LeftButton == ButtonState.Released && selectionRectangle != Rectangle.Empty)
{
+14 -4
View File
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using DepthsBelow.Component;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
@@ -14,6 +14,14 @@ namespace DepthsBelow
public Color Color;
public static Point Origin;
Stat soldierStat;
public Stat Stat
{
get { return soldierStat; }
set { soldierStat = value; }
}
private bool _selected = false; //I guess as in "currently doing something"
public bool select
@@ -29,7 +37,7 @@ namespace DepthsBelow
public Vector2 direction = Vector2.Zero;
public Shot(EntityManager entityManager)
public Shot(EntityManager entityManager, Stat _soldierStat)
: base(entityManager)
{
if (Texture == null)
@@ -37,6 +45,8 @@ namespace DepthsBelow
Transform.World.Origin = new Vector2(16, 16);
Stat = _soldierStat;
this.Color = Color.White;
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
AddComponent(rc);
@@ -46,7 +56,7 @@ namespace DepthsBelow
}
public static void LoadContent()
{
{
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot");
}
public override void Update(GameTime gameTime)
+33 -31
View File
@@ -1,23 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DepthsBelow.Component;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Text;
using DepthsBelow.Component;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace DepthsBelow
{
/// <summary>
/// Various global utility functions.
/// <summary>
/// Various global utility functions.
/// </summary>
static class Utility
{
/// <summary>
/// Calculate the chance of an entity with a Stat component to hit another unit.
/// </summary>
/// <param name="attacker">The attacking unit.</param>
/// <param name="defender">The recieving unit.</param>
/// <summary>
/// Calculate the chance of an entity with a Stat component to hit another unit.
/// </summary>
/// <param name="attacker">The attacking unit.</param>
/// <param name="defender">The recieving unit.</param>
/// <returns>Returns a hit chance percentage.</returns>
public static int CalculateHitChance(Entity attacker, Entity defender)
{
@@ -29,7 +29,9 @@ namespace DepthsBelow
}
int baseHitChance = shooting.GetAim;
int baseDodgeChance = dodging.GetDodge;
int basePenalty = shooting.Penalty((int)Vector2.Distance(attacker.GetComponent<Transform>().World.Position, defender.GetComponent<Transform>().World.Position) / Grid.TileSize);
int distance = (int)Vector2.Distance(attacker.GetComponent<Transform>().World.Position, defender.GetComponent<Transform>().World.Position);
int basePenalty = shooting.Penalty(distance / (Grid.TileSize / 2));
Console.WriteLine("Penalty = " + basePenalty);
int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
//Console.WriteLine(chanceToHit);
return chanceToHit;
@@ -45,23 +47,23 @@ namespace DepthsBelow
return true;
}
return false;
}*/
private static Texture2D blank;
public static void DrawLine(SpriteBatch batch, Color color, float width, Vector2 start, Vector2 end)
{
if (blank == null)
{
blank = new Texture2D(Core.GraphicsDeviceManager.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
blank.SetData(new[] { color });
}
float angle = (float)Math.Atan2(end.Y - start.Y, end.X - start.X);
float length = Vector2.Distance(start, end);
batch.Draw(blank, start, null, color,
angle, Vector2.Zero, new Vector2(length, width),
SpriteEffects.None, 0);
}
}*/
private static Texture2D blank;
public static void DrawLine(SpriteBatch batch, Color color, float width, Vector2 start, Vector2 end)
{
if (blank == null)
{
blank = new Texture2D(Core.GraphicsDeviceManager.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
blank.SetData(new[] { color });
}
float angle = (float)Math.Atan2(end.Y - start.Y, end.X - start.X);
float length = Vector2.Distance(start, end);
batch.Draw(blank, start, null, color,
angle, Vector2.Zero, new Vector2(length, width),
SpriteEffects.None, 0);
}
}
}