Merge branch 'master' of github.com:sippeangelo/DepthsBelow
This commit is contained in:
@@ -1,62 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace DepthsBelow.Component
|
|
||||||
{
|
|
||||||
class Shooting : Component
|
|
||||||
{
|
|
||||||
protected int stepsTaken = 0;
|
|
||||||
protected int distanceToTarget = 0;
|
|
||||||
protected int panic = 0;
|
|
||||||
protected int soldierAim = 0;
|
|
||||||
protected int weaponAccuracy = 0;
|
|
||||||
protected int enemyDodge = 0;
|
|
||||||
|
|
||||||
protected int penaltyRange = 5;
|
|
||||||
|
|
||||||
public Shooting(Entity parent) : base (parent)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool targetInSight()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int CalculateChance()
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
if (distance >= penaltyRange * 3)
|
|
||||||
{
|
|
||||||
penalty = 100;
|
|
||||||
}
|
|
||||||
else if (distance >= penaltyRange * 2)
|
|
||||||
{
|
|
||||||
distance -= penaltyRange * 2;
|
|
||||||
penalty = penaltyRange + penaltyRange * 3 + distance * 5;
|
|
||||||
}
|
|
||||||
else if (distance >= penaltyRange)
|
|
||||||
{
|
|
||||||
distance -= penaltyRange;
|
|
||||||
penalty = penaltyRange + distance * 3;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
penalty = distance;
|
|
||||||
}
|
|
||||||
return penalty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace DepthsBelow.Component
|
||||||
|
{
|
||||||
|
public class Stat : Component
|
||||||
|
{
|
||||||
|
protected int hp = 0;
|
||||||
|
protected int defence = 0;
|
||||||
|
protected int stepsTaken = 0;
|
||||||
|
protected int distanceToTarget = 0;
|
||||||
|
protected int panic = 0;
|
||||||
|
protected int soldierAim = 100;
|
||||||
|
protected int weaponAccuracy = 0;
|
||||||
|
protected int weaponStrength = 0;
|
||||||
|
protected int ammo = 0;
|
||||||
|
protected int enemyDodge = 0;
|
||||||
|
|
||||||
|
protected int penaltyRange = 5;
|
||||||
|
|
||||||
|
public int GetAim
|
||||||
|
{
|
||||||
|
get { return soldierAim + weaponAccuracy; }
|
||||||
|
set { soldierAim = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetDodge
|
||||||
|
{
|
||||||
|
get { return enemyDodge; }
|
||||||
|
set { enemyDodge = value; }
|
||||||
|
}
|
||||||
|
public int Life
|
||||||
|
{
|
||||||
|
get { return hp; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
hp = value;
|
||||||
|
if (hp <= 0) {
|
||||||
|
//If you kill me, I will become stronger than you can ever imagine.
|
||||||
|
Kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int Defence
|
||||||
|
{
|
||||||
|
get { return defence; }
|
||||||
|
set { defence = value; }
|
||||||
|
}
|
||||||
|
public int Strength
|
||||||
|
{
|
||||||
|
get { return weaponStrength; }
|
||||||
|
set { weaponStrength = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Kill()
|
||||||
|
{
|
||||||
|
hp = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Penalty(int distance)
|
||||||
|
{
|
||||||
|
return panic + GetPenalty(stepsTaken) + (int)(GetPenalty(distance) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stat(Entity parent) : base (parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool targetInSight()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetPenalty(int distance)
|
||||||
|
{
|
||||||
|
int penalty = 0;
|
||||||
|
if (distance >= penaltyRange * 3)
|
||||||
|
{
|
||||||
|
penalty = 100;
|
||||||
|
}
|
||||||
|
else if (distance >= penaltyRange * 2)
|
||||||
|
{
|
||||||
|
distance -= penaltyRange * 2;
|
||||||
|
penalty = penaltyRange + penaltyRange * 3 + distance * 5;
|
||||||
|
}
|
||||||
|
else if (distance >= penaltyRange)
|
||||||
|
{
|
||||||
|
distance -= penaltyRange;
|
||||||
|
penalty = penaltyRange + distance * 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
penalty = distance;
|
||||||
|
}
|
||||||
|
return penalty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -100,6 +100,8 @@ namespace DepthsBelow
|
|||||||
MouseInput.LoadContent();
|
MouseInput.LoadContent();
|
||||||
KeyboardInput = new KeyboardInput(this);
|
KeyboardInput = new KeyboardInput(this);
|
||||||
|
|
||||||
|
Swarm.Add(TestMonster);
|
||||||
|
|
||||||
TestMonster.X = 12;
|
TestMonster.X = 12;
|
||||||
TestMonster.Y = 4;
|
TestMonster.Y = 4;
|
||||||
|
|
||||||
@@ -146,18 +148,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;
|
||||||
|
|||||||
@@ -49,6 +49,12 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
var pfc = new PathFinder(this);
|
var pfc = new PathFinder(this);
|
||||||
AddComponent(pfc);
|
AddComponent(pfc);
|
||||||
|
|
||||||
|
stat.Life = 2;
|
||||||
|
stat.Defence = 0;
|
||||||
|
stat.Strength = 5;
|
||||||
|
stat.GetAim = 100;
|
||||||
|
stat.GetDodge = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Selected
|
public bool Selected
|
||||||
|
|||||||
@@ -61,6 +61,12 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
var pfc = new PathFinder(this);
|
var pfc = new PathFinder(this);
|
||||||
AddComponent(pfc);
|
AddComponent(pfc);
|
||||||
|
|
||||||
|
stat.Life = 10;
|
||||||
|
stat.Defence = 10;
|
||||||
|
stat.Strength = 10;
|
||||||
|
stat.GetAim = 100;
|
||||||
|
stat.GetDodge = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Selected
|
public bool Selected
|
||||||
@@ -98,6 +104,13 @@ namespace DepthsBelow
|
|||||||
soldierCollisions.Add(soldier.Transform.Grid);
|
soldierCollisions.Add(soldier.Transform.Grid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach (var enemy in core.Swarm)
|
||||||
|
{
|
||||||
|
if (!enemy.GetComponent<PathFinder>().IsMoving)
|
||||||
|
{
|
||||||
|
soldierCollisions.Add(enemy.Transform.Grid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var soldier in Squad)
|
foreach (var soldier in Squad)
|
||||||
{
|
{
|
||||||
@@ -114,6 +127,18 @@ namespace DepthsBelow
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach (var enemy in core.Swarm)
|
||||||
|
{
|
||||||
|
var pathFinder = enemy.GetComponent<PathFinder>();
|
||||||
|
var position = nextNode.Position;
|
||||||
|
if (enemy.Transform.Grid == position)
|
||||||
|
{
|
||||||
|
soldierCollisions.Add(enemy.Transform.Grid);
|
||||||
|
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
|
||||||
|
nextNode = GetComponent<PathFinder>().Next();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (nextNode != null)
|
if (nextNode != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
public static bool HitTest(Entity attacker, Entity defender, int chanceToHit)
|
||||||
|
{
|
||||||
|
Component.Stat shooting = attacker.GetComponent<Component.Stat>();
|
||||||
|
Component.Stat dodging = defender.GetComponent<Component.Stat>();
|
||||||
|
Random rand = new Random();
|
||||||
|
if (rand.Next(0, 100) < chanceToHit)
|
||||||
|
{
|
||||||
|
dodging.Life -= shooting.Strength - dodging.Defence / 2;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user