Added Stats, damage code, stuff

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-10-17 11:20:09 +02:00
parent 4f8a5ccdb2
commit 092dc176a8
4 changed files with 205 additions and 148 deletions
+38 -5
View File
@@ -7,23 +7,56 @@ 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 = 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()
public int GetAim
{
return (soldierAim + weaponAccuracy);
get { return soldierAim + weaponAccuracy; }
set { soldierAim = value; }
}
public int GetDodge()
public int GetDodge
{
return enemyDodge;
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)
+147 -141
View File
@@ -1,142 +1,148 @@
using System;
using System.Collections.Generic;
using DepthsBelow.Component;
using Microsoft.Xna.Framework;
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 int step
{
get { return currentStep; }
set
{
currentStep = value;
}
}
public SmallEnemy(Core core, ref List<SmallEnemy> swarm)
: base(core)
{
if (Texture == null)
LoadContent(core);
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);
AddComponent(cc);
var pfc = new PathFinder(this);
AddComponent(pfc);
}
public bool Selected
{
get { return _selected; }
set
{
_selected = value;
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
}
}
public static void LoadContent(Core core)
{
Texture = core.Content.Load<Texture2D>("images/Monster");
}
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>();
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;
}
}
}
foreach (var soldier in core.Squad)
{
var pathFinder = soldier.GetComponent<PathFinder>();
var position = nextNode.Position;
if (soldier.Transform.Grid == position)
{
soldierCollisions.Add(soldier.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;
if (Transform.World.X > nodeWorldPos.X)
Transform.World.X -= speed;
if (Transform.World.Y < nodeWorldPos.Y)
Transform.World.Y += speed;
if (Transform.World.Y > nodeWorldPos.Y)
Transform.World.Y -= speed;
if (Transform.World == nodeWorldPos)
{
if (currentStep < numberOfSteps)
{
currentStep++;
//lastLastNode = lastNode;
//lastNode = nextNode;
nextNode = GetComponent<PathFinder>().Next();
}
else
{
GetComponent<PathFinder>().Stop();
}
}
}
}
}
}
using System;
using System.Collections.Generic;
using DepthsBelow.Component;
using Microsoft.Xna.Framework;
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 int step
{
get { return currentStep; }
set
{
currentStep = value;
}
}
public SmallEnemy(Core core, ref List<SmallEnemy> swarm)
: base(core)
{
if (Texture == null)
LoadContent(core);
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);
AddComponent(cc);
var pfc = new PathFinder(this);
AddComponent(pfc);
stat.Life = 2;
stat.Defence = 0;
stat.Strength = 5;
stat.GetAim = 100;
stat.GetDodge = 10;
}
public bool Selected
{
get { return _selected; }
set
{
_selected = value;
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
}
}
public static void LoadContent(Core core)
{
Texture = core.Content.Load<Texture2D>("images/Monster");
}
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>();
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;
}
}
}
foreach (var soldier in core.Squad)
{
var pathFinder = soldier.GetComponent<PathFinder>();
var position = nextNode.Position;
if (soldier.Transform.Grid == position)
{
soldierCollisions.Add(soldier.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;
if (Transform.World.X > nodeWorldPos.X)
Transform.World.X -= speed;
if (Transform.World.Y < nodeWorldPos.Y)
Transform.World.Y += speed;
if (Transform.World.Y > nodeWorldPos.Y)
Transform.World.Y -= speed;
if (Transform.World == nodeWorldPos)
{
if (currentStep < numberOfSteps)
{
currentStep++;
//lastLastNode = lastNode;
//lastNode = nextNode;
nextNode = GetComponent<PathFinder>().Next();
}
else
{
GetComponent<PathFinder>().Stop();
}
}
}
}
}
}
}
+6
View File
@@ -61,6 +61,12 @@ namespace DepthsBelow
var pfc = new PathFinder(this);
AddComponent(pfc);
stat.Life = 10;
stat.Defence = 10;
stat.Strength = 10;
stat.GetAim = 100;
stat.GetDodge = 20;
}
public bool Selected
+14 -2
View File
@@ -16,11 +16,23 @@ namespace DepthsBelow
{
return 0;
}
int baseHitChance = shooting.GetAim();
int baseDodgeChance = dodging.GetDodge();
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;
}
}
}