Exemple #1
0
        /// <summary>
        /// basic update with adition of droping land mines when reaching target and deciding wether to shot at player
        /// </summary>
        /// <param name="playerPos">The player position.</param>
        ///<seealso cref="Tank.Update(Vector2)"/>
        public override bool Update(Vector2 playerPos)
        {
            //drop landmine if reached target
            if (BasePosition == target)
            {
                //drop landmine
                GameScene.AddLandMine(new RedMine(BasePosition - Dimensions / 2f));

                //calculate new target positon
                target = SetTarget();
            }

            //if this tank can see player shoot and follow him
            if ((BasePosition - playerPos).LengthSquared() <= Math.Pow(viewRange, 2))
            {
                //turn on cannon and call Tank update with player as target
                Cannon.Active = true;
                return(Update(target, playerPos));
            }

            //turn cannon off and call Tank update with the random point(target) as the target
            Cannon.Active = false;
            return(base.Update(target));
        }