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>(); // Collision with units at a standstill //foreach (var soldier in Squad) //{ // if (soldier != this) // { // if (!soldier.GetComponent<PathFinder>().IsMoving) // { // soldierCollisions.Add(soldier.Transform.Grid); // } // if (soldier.Transform.Grid == nextNode.Position) // { // GetComponent<PathFinder>().RecreatePath(soldierCollisions); // nextNode = GetComponent<PathFinder>().Next(); // break; // } // } //} // Collision with moving units //foreach (var soldier in Squad) //{ // if (soldier != this) // { // 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 (AP < NumberOfActionPoints) //{ //AP++; lastLastNode = lastNode; lastNode = nextNode; nextNode = GetComponent<PathFinder>().Next(); //} /*else { GetComponent<PathFinder>().Stop(); }*/ } } } if (Fired == true) { fireTimer += gameTime.ElapsedGameTime.Milliseconds; if (fireTimer > timeSpentFired) { fireTimer = 0; Fired = false; } } }
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>(); // Collision with moving units 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; } } } 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<Component.Transform>().World.Rotation = MathHelper.ToRadians(0); } if (Transform.World.X > nodeWorldPos.X) { Transform.World.X -= speed; GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(180); } if (Transform.World.Y < nodeWorldPos.Y) { Transform.World.Y += speed; GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(90); } if (Transform.World.Y > nodeWorldPos.Y) { Transform.World.Y -= speed; GetComponent<Component.Transform>().World.Rotation = MathHelper.ToRadians(270); } if (Transform.World == nodeWorldPos) { if (currentStep < numberOfSteps) { currentStep++; //lastLastNode = lastNode; //lastNode = nextNode; nextNode = GetComponent<PathFinder>().Next(); } else { GetComponent<PathFinder>().Stop(); } foreach (var entity in EntityManager.Entities) { if (entity is Soldier) { if (entity.GetComponent<Component.Collision>().Rectangle.Intersects(this.GetComponent<Component.Collision>().Rectangle)) { if (AttackedThisTurn == false) { if (Utility.AttackTest(this.GetComponent<Component.Stat>(), entity, Utility.CalculateHitChance(this.GetComponent<Component.Stat>(), this.Transform.World.Position, entity))) { AttackedThisTurn = true; break; } } } } } } } } }