Added Utility, Stat, removed FindDistance(Core)
This commit is contained in:
+18
-12
@@ -5,7 +5,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace DepthsBelow.Component
|
namespace DepthsBelow.Component
|
||||||
{
|
{
|
||||||
class Shooting : Component
|
public class Stat : Component
|
||||||
{
|
{
|
||||||
protected int stepsTaken = 0;
|
protected int stepsTaken = 0;
|
||||||
protected int distanceToTarget = 0;
|
protected int distanceToTarget = 0;
|
||||||
@@ -16,7 +16,22 @@ namespace DepthsBelow.Component
|
|||||||
|
|
||||||
protected int penaltyRange = 5;
|
protected int penaltyRange = 5;
|
||||||
|
|
||||||
public Shooting(Entity parent) : base (parent)
|
public int GetAim()
|
||||||
|
{
|
||||||
|
return (soldierAim + weaponAccuracy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetDodge()
|
||||||
|
{
|
||||||
|
return enemyDodge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Penalty(int distance)
|
||||||
|
{
|
||||||
|
return panic + GetPenalty(stepsTaken) + (int)(GetPenalty(distance) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stat(Entity parent) : base (parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -26,16 +41,7 @@ namespace DepthsBelow.Component
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CalculateChance()
|
public int GetPenalty(int distance)
|
||||||
{
|
|
||||||
int baseHitChance = soldierAim + weaponAccuracy;
|
|
||||||
int baseDodgeChance = panic + enemyDodge;
|
|
||||||
int basePenalty = ReturnPenalty(stepsTaken) + (int)(ReturnPenalty(distanceToTarget) / 2);
|
|
||||||
int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
|
|
||||||
return chanceToHit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ReturnPenalty(int distance)
|
|
||||||
{
|
{
|
||||||
int penalty = 0;
|
int penalty = 0;
|
||||||
if (distance >= penaltyRange * 3)
|
if (distance >= penaltyRange * 3)
|
||||||
@@ -146,18 +146,6 @@ namespace DepthsBelow
|
|||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int FindDistance(Vector2 target, Vector2 start)
|
|
||||||
{
|
|
||||||
Vector2 combine = new Vector2(target.X - start.X, target.Y - start.Y);
|
|
||||||
|
|
||||||
int result = 0;
|
|
||||||
int firstRestult = (int)Math.Sqrt((int)combine.X^2 + (int)combine.Y^2);
|
|
||||||
|
|
||||||
result = (int)Vector2.Distance(target, start);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called when the game should draw itself.
|
/// This is called when the game should draw itself.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<RootNamespace>DepthsBelow</RootNamespace>
|
<RootNamespace>DepthsBelow</RootNamespace>
|
||||||
<AssemblyName>DepthsBelow</AssemblyName>
|
<AssemblyName>DepthsBelow</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||||
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
|
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
|
||||||
<XnaPlatform>Windows</XnaPlatform>
|
<XnaPlatform>Windows</XnaPlatform>
|
||||||
<XnaProfile>HiDef</XnaProfile>
|
<XnaProfile>HiDef</XnaProfile>
|
||||||
@@ -125,7 +125,7 @@
|
|||||||
<Compile Include="Interface.cs" />
|
<Compile Include="Interface.cs" />
|
||||||
<Compile Include="Lua.cs" />
|
<Compile Include="Lua.cs" />
|
||||||
<Compile Include="Shot.cs" />
|
<Compile Include="Shot.cs" />
|
||||||
<Compile Include="Component\Shooting.cs" />
|
<Compile Include="Component\Stat.cs" />
|
||||||
<Compile Include="GUIManager.cs" />
|
<Compile Include="GUIManager.cs" />
|
||||||
<Compile Include="GUI\Button.cs" />
|
<Compile Include="GUI\Button.cs" />
|
||||||
<Compile Include="GUI\Frame.cs" />
|
<Compile Include="GUI\Frame.cs" />
|
||||||
@@ -148,6 +148,7 @@
|
|||||||
<Compile Include="SmallEnemy.cs" />
|
<Compile Include="SmallEnemy.cs" />
|
||||||
<Compile Include="Soldier.cs" />
|
<Compile Include="Soldier.cs" />
|
||||||
<Compile Include="Component\PixelTransform.cs" />
|
<Compile Include="Component\PixelTransform.cs" />
|
||||||
|
<Compile Include="Utility.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Game.ico" />
|
<Content Include="Game.ico" />
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace DepthsBelow
|
|||||||
public Component.Transform Transform;
|
public Component.Transform Transform;
|
||||||
public Component.PixelTransform pixelTransform;
|
public Component.PixelTransform pixelTransform;
|
||||||
public Component.GridTransform gridTransform;
|
public Component.GridTransform gridTransform;
|
||||||
|
public Component.Stat stat;
|
||||||
public int X
|
public int X
|
||||||
{
|
{
|
||||||
get { return this.Transform.Grid.X; }
|
get { return this.Transform.Grid.X; }
|
||||||
@@ -42,6 +43,8 @@ namespace DepthsBelow
|
|||||||
AddComponent(pixelTransform);
|
AddComponent(pixelTransform);
|
||||||
gridTransform = new Component.GridTransform(this);
|
gridTransform = new Component.GridTransform(this);
|
||||||
AddComponent(gridTransform);
|
AddComponent(gridTransform);
|
||||||
|
stat = new Component.Stat(this);
|
||||||
|
AddComponent(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetComponent<T>() where T : Component.Component
|
public T GetComponent<T>() where T : Component.Component
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace DepthsBelow
|
|||||||
Core core;
|
Core core;
|
||||||
bool Enter = false;
|
bool Enter = false;
|
||||||
bool turn;
|
bool turn;
|
||||||
int checkerSpeed = 1;
|
int checkerSpeed = 2;
|
||||||
|
|
||||||
public KeyboardInput(Core core)
|
public KeyboardInput(Core core)
|
||||||
{
|
{
|
||||||
@@ -48,13 +48,14 @@ namespace DepthsBelow
|
|||||||
core.TestMonster.step = 0;
|
core.TestMonster.step = 0;
|
||||||
core.PlayerTurn = false;
|
core.PlayerTurn = false;
|
||||||
Point target = Point.Zero;
|
Point target = Point.Zero;
|
||||||
int distance = 7000;
|
float distance = 7000;
|
||||||
foreach (var unit in core.Squad)
|
foreach (var unit in core.Squad)
|
||||||
{
|
{
|
||||||
Vector2 soldier = new Vector2(unit.Transform.Grid.X, unit.Transform.Grid.Y);
|
Vector2 soldier = new Vector2(unit.Transform.Grid.X, unit.Transform.Grid.Y);
|
||||||
Vector2 monster = new Vector2(core.TestMonster.Transform.Grid.X, core.TestMonster.Transform.Grid.Y);
|
Vector2 monster = new Vector2(core.TestMonster.Transform.Grid.X, core.TestMonster.Transform.Grid.Y);
|
||||||
|
|
||||||
int newDistance = core.FindDistance(soldier, monster);
|
float newDistance = Vector2.Distance(soldier, monster);
|
||||||
|
|
||||||
if (newDistance < distance)
|
if (newDistance < distance)
|
||||||
{
|
{
|
||||||
target = unit.Transform.Grid;
|
target = unit.Transform.Grid;
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
|
namespace DepthsBelow
|
||||||
|
{
|
||||||
|
static class Utility
|
||||||
|
{
|
||||||
|
public static int CalculateHitChance(Entity attacker, Entity defender)
|
||||||
|
{
|
||||||
|
Component.Stat shooting = attacker.GetComponent<Component.Stat>();
|
||||||
|
Component.Stat dodging = defender.GetComponent<Component.Stat>();
|
||||||
|
if (shooting == null || dodging == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int baseHitChance = shooting.GetAim();
|
||||||
|
int baseDodgeChance = dodging.GetDodge();
|
||||||
|
int basePenalty = shooting.Penalty((int)Vector2.Distance(attacker.GetComponent<Component.Transform>().World.Position, defender.GetComponent<Component.Transform>().World.Position) / Grid.TileSize);
|
||||||
|
int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
|
||||||
|
return chanceToHit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user