public void ActiveIA(CCEnemyBase enemy, CCPlayerBase player)
 {
     enemy.IsIA = true;
     enemy.IADesiredActionState = EnemyDesiredActionState.SearchingTarget;
     enemy.IAPersonalityState = EnemyPersonalityState.Attacking; //(EnemyPersonalityState)CCRandom.Next(1, 3);
     enemy.IATarget = new CCPoint(enemy.PositionX, (int)CCRandom.GetRandomFloat(player.PositionY - 50f, player.PositionY + 50f));
 }
        public void UpdateShipIA(CCEnemyBase enemy, CCPlayerBase player, CCSize wSize, int PLAYER_SPEED)
        {
            if (enemy.IsIA)
            {

                enemy.PositionX -= (PLAYER_SPEED + enemy.VELOCITY + enemy.VELOCITY + CCRandom.Next(1, 3));

                //Esta dentro de su rango;
                if (enemy.IADesiredActionState == EnemyDesiredActionState.Firing)
                {
                    if (ACTUAL_DELAY <= DELAY_SHOOT)
                        ACTUAL_DELAY++;
                    else
                    {
                        enemy.IADesiredActionState = EnemyDesiredActionState.SearchingTarget;
                        ACTUAL_DELAY = 0;
                    }
                }

                if (enemy.IAPersonalityState == EnemyPersonalityState.Suicide)
                {
                    if (enemy.PositionY > player.PositionY)
                        enemy.PositionY -= CCRandom.Next(1, 3);
                    else if (enemy.PositionY < player.PositionY)
                        enemy.PositionY += CCRandom.Next(1, 3);
                }
                else if (enemy.IAPersonalityState == EnemyPersonalityState.Attacking)
                {

                    //Si la posicion
                    if (enemy.IATarget.Y == enemy.Position.Y)
                        enemy.IATarget.Y = (int)CCRandom.GetRandomFloat(player.PositionY - 50f, player.PositionY + 50f);

                    if (enemy.PositionY > enemy.IATarget.Y)
                        enemy.PositionY -= CCRandom.Next(1, 3);
                    else if (enemy.PositionY < enemy.IATarget.Y)
                        enemy.PositionY += CCRandom.Next(1, 3);

                }

                if (enemy.PositionY > player.PositionY - 30 && enemy.PositionY < player.PositionY + 30 && enemy.PositionX < wSize.Width - 15)
                {

                    CCEventCustom eventC = new CCEventCustom(CCBeatEmUpGameLayer.EVENT_ENEMY_ID);
                    eventC.UserData = enemy;

                }

                if (player.PositionX > enemy.PositionX - 100)
                {
                    if (enemy.IADesiredActionState != EnemyDesiredActionState.OutOfRange)
                        enemy.IADesiredActionState = EnemyDesiredActionState.OutOfRange;
                }
            }
        }
 //        private virtual void Shoot(ShootType tipo, CCPoint initialPosition, bool isPlayer)
 //        {
 //            if (tipo == ShootType.Meteoro)
 //            {
 //#if WINDOWS_PHONE
 //                Deployment.Current.Dispatcher.BeginInvoke(() =>
 //                {
 //                    ShootMeteor meteorof = null;
 //                    meteorof = new ShootMeteor(isPlayer);
 //                    meteorof.Deleted += (s) =>
 //                    {
 //                        RemoveShoot(s);
 //                    };
 //                    meteorof.Position = initialPosition;
 //                    if (isPlayer)
 //                        AddShoot(meteorof);
 //                    else
 //                        AddEnemyShoot(meteorof);
 //                });
 //#else
 //                CCShootBase meteorof = null;
 //                meteorof = new CCSho(initialPosition, isPlayer);
 //                //meteorof.Deleted += (s) =>
 //                //{
 //                //    RemoveShoot(s);
 //                //};
 //                if (isPlayer)
 //                    AddShoot(meteorof);
 //                else
 //                    AddEnemyShoot(meteorof);
 //#endif
 //            }
 //        }
 public void PlayerNextFire(CCPlayerBase Player1)
 {
     Player1.NextFire();
 }
 public void PlayerFire(CCPlayerBase Player1)
 {
     Player1.Fire();
 }
        public void CheckEnemyCollition(CCPlayerBase Player1)
        {
            if (Player1 == null)
                return;

            if (!Player1.HasCollision)
            {

                var deletedShoot = new List<CCShootBase>();
                var deletedEnemy = new List<CCNode>();

                bool enemydeleted = false;

                CCEnemyBase[] cacheEnemies = new CCEnemyBase[Enemies.Count];
                Enemies.CopyTo(cacheEnemies);

                CCShootBase[] cacheShoots = new CCShootBase[Shoots.Count];
                Shoots.CopyTo(cacheShoots);

                foreach (CCEnemyBase tmpEnemy in cacheEnemies) //cacheEnemies.Where(s => (typeof(EnemyMeteor) == s.GetType() && (s as EnemyMeteor).CheckCollition) || (typeof(EnemyShip) == s.GetType() && (s as EnemyShip).CheckCollition)))
                {
                    enemydeleted = false;

                    //COMPROBAMOS LOS DISPAROS QUE HAN IMPACTADO CON EL ENEMIGO
                    foreach (var tmpShoot in cacheShoots)
                    {

                        //TODO: MEJORAR Y PONER UN CIRCULO CON RADIO ALTO Y ANCHO en el caso de los asteorides
                        //AÑADIMOS LA RRAY DE ELEMENTOS PARA BOTTAR
                        if (tmpEnemy.BoundingBox.IntersectsRect(tmpShoot.BoundingBox))
                        {

                            deletedShoot.Add(tmpShoot);
                            deletedEnemy.Add(tmpEnemy);
                            enemydeleted = true; //SOLO ES PARA EL ENEMIGO
                        }
                    }

                    if (enemydeleted) //SI HEMOS IMPACTADO EN ALGUN ENEMIGO LO BORRAMOS
                    {

                        //ELIMINAMOS EL DISPARO
                        foreach (var tmpShoot in deletedShoot)
                            RemoveShoot(tmpShoot);// tmpShoot.DeleteElement(); //Eliminamos el disparo que ha impactado con el enemigo

                        if (tmpEnemy.GetType() == typeof(CCEnemyBase))
                        {
                            if ((tmpEnemy as CCEnemyBase).RemoveLife(1))
                            {
                                EnemyKills++;
                                DeleteEnemy(tmpEnemy, true);
                            }
                        }
                        else if (tmpEnemy.GetType() == typeof(CCEnemyBase))
                        {
                            EnemyKills++;
                            DeleteEnemy(tmpEnemy, true);
                        }

                    }
                    else //SI EL ENEMIGO NO HA SIDO DESTRUIDO
                    {

                        //COMPROBAMOS QUE SALGA FUERA DE PANTALLA
                        if (tmpEnemy.PositionX < -(3 + tmpEnemy.ContentSize.Width))
                        {
                            DeleteEnemy(tmpEnemy, false);
                            enemydeleted = true;
                        }

                        //Comprobamos que esté activada la colision
                        if ((typeof(CCEnemyBase) == tmpEnemy.GetType() && (tmpEnemy as CCEnemyBase).CheckCollition))
                            //ENEMIGO CHOCA CON NAVE
                            if (!enemydeleted && Player1.BoundingBox.IntersectsRect(tmpEnemy.BoundingBox))
                            {

                                //TODO: COLLISION DETECTED EVENT
                                //   CollitionDetected();
                            }

                    }

                }

            }
        }
 public void AddPlayer(CCPlayerBase newPlayer, CCPoint initialPosition)
 {
     AddPlayer(newPlayer, initialPosition, (int)eTAG_DEPTH.PLAYER_LAYER);
 }
        public void AddPlayer(CCPlayerBase newPlayer, CCPoint initialPosition, int depth)
        {
            if (Players.Find((tmp) => tmp == newPlayer) != null)
            {
                Console.WriteLine("CANNOT ADD PLAYER. ITS ON LAYER");
                return;
            }

            CCGameSettingsBase.Instance.Player1 = newPlayer; //TODO: ARRAY DE PLAYERS

            Players.Add(newPlayer); //Add to players array

            AddChild(newPlayer, depth);
            newPlayer.Position = initialPosition;
            Console.WriteLine("PLAYER 1 ADDED TO SHIP LAYER");
        }