예제 #1
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            //CheckInput(); Now from campaignscreen
            CheckAlive();

            if (currentallies > oldallies & (currentallies <= maximum))
            {
                oldallies = currentallies;
                if (oldallies % 4 == 1)
                {
                    offsetX = 1;
                    offsetY = 1;
                }
                if (oldallies % 4 == 2)
                {
                    offsetX = -1;
                    offsetY = 1;
                }
                if (oldallies % 4 == 3)
                {
                    offsetX = 1;
                    offsetY = -1;
                }
                if (oldallies % 4 == 0)
                {
                    offsetX = -1;
                    offsetY = -1;
                }
                AllyComponent tempAlly = new AllyComponent(this.Game, offsetX, offsetY, playerLevel, iMap, nearestTent, spriteBatch, sprite);
                allies.Add(tempAlly);
            }

            foreach (AllyComponent thisAlly in allies)
            {
                if (thisAlly.alive == true)
                {
                    thisAlly.formation = formation;
                    thisAlly.mobs      = mobs;
                    thisAlly.allies    = allies;
                    thisAlly.Update(gameTime);
                    thisAlly.playerposition = playerposition;
                }
            }

            base.Update(gameTime);
        }
예제 #2
0
        private bool hasAggro(int[] position, int[] playerposition)
        {
            int  Count      = 0;
            bool nearPlayer = false;

            if (((Math.Abs(playerposition[0] - position[0]) + (Math.Abs(playerposition[1] - position[1])))) < 8)
            {
                nearPlayer = true;
            }

            int playerdistance = (((Math.Abs(playerposition[0] - position[0]) + (Math.Abs(playerposition[1] - position[1])))));

            foreach (AllyComponent thisAlly in allies)
            {
                if (thisAlly.alive)
                {
                    if (((Math.Abs(thisAlly.position[0] - position[0]) + (Math.Abs(thisAlly.position[1] - position[1]))) < playerdistance))
                    {
                        targetedAlly = thisAlly;
                        Count       += 1;
                    }
                }
            }


            if (Count > 0)
            {
                targetAlly = true;
            }
            else
            {
                targetAlly = false;
            }

            return(nearPlayer);
        }