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 public class Stat : Component
{ {
protected int hp = 0;
protected int defence = 0;
protected int stepsTaken = 0; protected int stepsTaken = 0;
protected int distanceToTarget = 0; protected int distanceToTarget = 0;
protected int panic = 0; protected int panic = 0;
protected int soldierAim = 0; protected int soldierAim = 100;
protected int weaponAccuracy = 0; protected int weaponAccuracy = 0;
protected int weaponStrength = 0;
protected int ammo = 0;
protected int enemyDodge = 0; protected int enemyDodge = 0;
protected int penaltyRange = 5; 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) public int Penalty(int distance)
+147 -141
View File
@@ -1,142 +1,148 @@
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.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(Core core, ref List<SmallEnemy> swarm) public SmallEnemy(Core core, ref List<SmallEnemy> swarm)
: base(core) : base(core)
{ {
if (Texture == null) if (Texture == null)
LoadContent(core); LoadContent(core);
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);
}
stat.Life = 2;
public bool Selected stat.Defence = 0;
{ stat.Strength = 5;
get { return _selected; } stat.GetAim = 100;
set stat.GetDodge = 10;
{ }
_selected = value;
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color; public bool Selected
} {
} get { return _selected; }
set
public static void LoadContent(Core core) {
{ _selected = value;
Texture = core.Content.Load<Texture2D>("images/Monster"); GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
} }
}
public override void Update(GameTime gameTime)
{ public static void LoadContent(Core core)
base.Update(gameTime); {
Texture = core.Content.Load<Texture2D>("images/Monster");
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f; }
if (nextNode == null) public override void Update(GameTime gameTime)
nextNode = GetComponent<PathFinder>().Next(); {
base.Update(gameTime);
if (nextNode != null)
{ float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
List<Point> soldierCollisions = new List<Point>();
if (nextNode == null)
foreach (var body in Swarm) nextNode = GetComponent<PathFinder>().Next();
{
if (body != this) if (nextNode != null)
{ {
if (body.Transform.Grid == nextNode.Position) List<Point> soldierCollisions = new List<Point>();
{
soldierCollisions.Add(body.Transform.Grid); foreach (var body in Swarm)
GetComponent<PathFinder>().RecreatePath(soldierCollisions); {
nextNode = GetComponent<PathFinder>().Next(); if (body != this)
break; {
} if (body.Transform.Grid == nextNode.Position)
} {
} soldierCollisions.Add(body.Transform.Grid);
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
foreach (var soldier in core.Squad) nextNode = GetComponent<PathFinder>().Next();
{ break;
var pathFinder = soldier.GetComponent<PathFinder>(); }
var position = nextNode.Position; }
if (soldier.Transform.Grid == position) }
{
soldierCollisions.Add(soldier.Transform.Grid); foreach (var soldier in core.Squad)
GetComponent<PathFinder>().RecreatePath(soldierCollisions); {
nextNode = GetComponent<PathFinder>().Next(); var pathFinder = soldier.GetComponent<PathFinder>();
break; var position = nextNode.Position;
} if (soldier.Transform.Grid == position)
} {
soldierCollisions.Add(soldier.Transform.Grid);
if (nextNode != null) GetComponent<PathFinder>().RecreatePath(soldierCollisions);
{ nextNode = GetComponent<PathFinder>().Next();
var nodeWorldPos = Grid.GridToWorld(nextNode.Position); break;
// HACK: Make this work properly with other speeds... }
float speed = 4f; }
if (Transform.World.X < nodeWorldPos.X)
Transform.World.X += speed; if (nextNode != null)
if (Transform.World.X > nodeWorldPos.X) {
Transform.World.X -= speed; var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
if (Transform.World.Y < nodeWorldPos.Y) // HACK: Make this work properly with other speeds...
Transform.World.Y += speed; float speed = 4f;
if (Transform.World.Y > nodeWorldPos.Y) if (Transform.World.X < nodeWorldPos.X)
Transform.World.Y -= speed; Transform.World.X += speed;
if (Transform.World.X > nodeWorldPos.X)
if (Transform.World == nodeWorldPos) Transform.World.X -= speed;
{ if (Transform.World.Y < nodeWorldPos.Y)
if (currentStep < numberOfSteps) Transform.World.Y += speed;
{ if (Transform.World.Y > nodeWorldPos.Y)
currentStep++; Transform.World.Y -= speed;
//lastLastNode = lastNode;
//lastNode = nextNode; if (Transform.World == nodeWorldPos)
nextNode = GetComponent<PathFinder>().Next(); {
} if (currentStep < numberOfSteps)
else {
{ currentStep++;
GetComponent<PathFinder>().Stop(); //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); 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
+14 -2
View File
@@ -16,11 +16,23 @@ namespace DepthsBelow
{ {
return 0; return 0;
} }
int baseHitChance = shooting.GetAim(); int baseHitChance = shooting.GetAim;
int baseDodgeChance = dodging.GetDodge(); 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 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; int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
return chanceToHit; 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;
}
} }
} }