From 9ba26cae70b92ca4a275474d57c9b097864e8e3c Mon Sep 17 00:00:00 2001 From: Niklas Ulf Anders Cullberg Date: Mon, 29 Oct 2012 15:05:10 +0100 Subject: [PATCH] People die when they are killed This means that enemies can now kill the players without mercy. --- DepthsBelow/DepthsBelow/SmallEnemy.cs | 340 +++++++++++++------------- 1 file changed, 171 insertions(+), 169 deletions(-) diff --git a/DepthsBelow/DepthsBelow/SmallEnemy.cs b/DepthsBelow/DepthsBelow/SmallEnemy.cs index 88d4953..e47a19f 100755 --- a/DepthsBelow/DepthsBelow/SmallEnemy.cs +++ b/DepthsBelow/DepthsBelow/SmallEnemy.cs @@ -1,170 +1,172 @@ -using System; -using System.Collections.Generic; -using DepthsBelow.Component; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; -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 Swarm; - - private PathFinder.Node nextNode; - - public int numberOfSteps = 5; - public int currentStep = 0; - - public int step - { - get { return currentStep; } - set - { - currentStep = value; - } - } - - public SmallEnemy(EntityManager entityManager, ref List swarm) - : base(entityManager) - { - if (Texture == null) - LoadContent(); - - 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); - - var stat = new Component.Stat(this) - { - Life = 2, - Defence = 2, - Strength = 5000, - GetAim = 100, - GetDodge = 50 - }; - AddComponent(stat); - } - public override void Remove() - { - Swarm.Remove(this); - - base.Remove(); - } - - public bool Selected - { - get { return _selected; } - set - { - _selected = value; - GetComponent().Color = (value) ? Color.Blue : this.Color; - } - } - - public static void LoadContent() - { - Texture = GameServices.GetService().Load("images/Monster"); - } - - public override void Update(GameTime gameTime) - { - base.Update(gameTime); - - float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f; - - if (nextNode == null) - nextNode = GetComponent().Next(); - - if (nextNode != null) - { - List soldierCollisions = new List(); - - // Collision with moving units - foreach (var body in Swarm) - { - if (body != this) - { - if (body.Transform.Grid == nextNode.Position) - { - soldierCollisions.Add(body.Transform.Grid); - GetComponent().RecreatePath(soldierCollisions); - nextNode = GetComponent().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; - GetComponent().World.Rotation = MathHelper.ToRadians(0); - } - if (Transform.World.X > nodeWorldPos.X) - { - Transform.World.X -= speed; - GetComponent().World.Rotation = MathHelper.ToRadians(180); - } - if (Transform.World.Y < nodeWorldPos.Y) - { - Transform.World.Y += speed; - GetComponent().World.Rotation = MathHelper.ToRadians(90); - } - if (Transform.World.Y > nodeWorldPos.Y) - { - Transform.World.Y -= speed; - GetComponent().World.Rotation = MathHelper.ToRadians(270); - } - if (Transform.World == nodeWorldPos) - { - if (currentStep < numberOfSteps) - { - currentStep++; - //lastLastNode = lastNode; - //lastNode = nextNode; - nextNode = GetComponent().Next(); - } - else - { - foreach (var entity in entityManager.Entities) { - if (entity is Soldier) - { - if (entity.GetComponent().Rectangle.Intersects(this.GetComponent().Rectangle)) - { - if (Utility.AttackTest(this.GetComponent(), entity, Utility.CalculateHitChance(this.GetComponent(), this.Transform.World.Position, entity))) - { - break; - } - } - } - } - GetComponent().Stop(); - } - } - } - - } - } - } +using System; +using System.Collections.Generic; +using DepthsBelow.Component; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +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 Swarm; + + private PathFinder.Node nextNode; + + public int numberOfSteps = 5; + public int currentStep = 0; + + public int step + { + get { return currentStep; } + set + { + currentStep = value; + } + } + + public SmallEnemy(EntityManager entityManager, ref List swarm) + : base(entityManager) + { + if (Texture == null) + LoadContent(); + + 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); + + var stat = new Component.Stat(this) + { + Life = 2, + Defence = 2, + Strength = 5000, + GetAim = 100, + GetDodge = 50 + }; + AddComponent(stat); + } + public override void Remove() + { + Swarm.Remove(this); + + base.Remove(); + } + + public bool Selected + { + get { return _selected; } + set + { + _selected = value; + GetComponent().Color = (value) ? Color.Blue : this.Color; + } + } + + public static void LoadContent() + { + Texture = GameServices.GetService().Load("images/Monster"); + } + + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + + float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f; + + if (nextNode == null) + nextNode = GetComponent().Next(); + + if (nextNode != null) + { + List soldierCollisions = new List(); + + // Collision with moving units + foreach (var body in Swarm) + { + if (body != this) + { + if (body.Transform.Grid == nextNode.Position) + { + soldierCollisions.Add(body.Transform.Grid); + GetComponent().RecreatePath(soldierCollisions); + nextNode = GetComponent().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; + GetComponent().World.Rotation = MathHelper.ToRadians(0); + } + if (Transform.World.X > nodeWorldPos.X) + { + Transform.World.X -= speed; + GetComponent().World.Rotation = MathHelper.ToRadians(180); + } + if (Transform.World.Y < nodeWorldPos.Y) + { + Transform.World.Y += speed; + GetComponent().World.Rotation = MathHelper.ToRadians(90); + } + if (Transform.World.Y > nodeWorldPos.Y) + { + Transform.World.Y -= speed; + GetComponent().World.Rotation = MathHelper.ToRadians(270); + } + if (Transform.World == nodeWorldPos) + { + if (currentStep < numberOfSteps) + { + currentStep++; + //lastLastNode = lastNode; + //lastNode = nextNode; + nextNode = GetComponent().Next(); + } + else + { + + GetComponent().Stop(); + } + foreach (var entity in entityManager.Entities) + { + if (entity is Soldier) + { + if (entity.GetComponent().Rectangle.Intersects(this.GetComponent().Rectangle)) + { + if (Utility.AttackTest(this.GetComponent(), entity, Utility.CalculateHitChance(this.GetComponent(), this.Transform.World.Position, entity))) + { + break; + } + } + } + } + } + } + + } + } + } } \ No newline at end of file