Esempio n. 1
0
        /// <summary>
        /// Próbuje zaatkaowaæ samolot gracza. Najpierw sprawdza mo¿liwoœæ ataku rakiet¹
        /// a póŸniej dzia³kiem.
        /// </summary>
        private void AttackUserPlane(Plane userPlane, float scaleFactor)
        {
            //return; //chwilowo do testów
            //sprawdzam czy samolot nie jest za daleko, ¿eby atakowaæ

            UpdateDebugInfo("AttackUserPlane", true.ToString());

            // staraj sie dogonic samolot gracza
            if (IsTurnedTowardsUserPlane(userPlane) && Speed < GetConsts().Speed * 1.4f)
            {
                Speed += 0.8f * scaleFactor;
            }

            if (!IsTurnedTowardsUserPlane(userPlane) && Speed > minFlyingSpeed)
            {
                Speed -= 0.8f * scaleFactor;
            }


            if (Math.Abs(Center.X - level.UserPlane.Center.X) > GetConsts().ViewRange)
            {
                return;
            }

            UpdateDebugInfo("AttackUserPlane-Distance", true.ToString());


            if (this.weaponManager.RocketCount > 0 && Rocket.CanHitEnemyPlane(this, level.UserPlane, 100 - GetConsts().Accuracy, false) != MissileBase.CollisionDirectionLocation.NONE) //najpierw próbuje strzeliæ rakiet¹
            {
                if (warCryTimer > warCryTimerMin)
                {
                    level.Controller.OnWarCry(this);
                    warCryTimer = 0;
                }
                FireRocket();
            }
            else
            {
                UpdateDebugInfo("AttackUserPlane-GunAiming", true.ToString());

                MissileBase.CollisionDirectionLocation coll = GunBullet.CanHitEnemyPlane(this, level.UserPlane, 100 - GetConsts().Accuracy, this.HasBiDirectionalGun);
                if (coll != MissileBase.CollisionDirectionLocation.NONE)
                {
                    if (warCryTimer > warCryTimerMin)
                    {
                        level.Controller.OnWarCry(this);
                        warCryTimer = 0;
                    }
                    //Console.WriteLine(this.Name + ": AttackUserPlane -> can hit");
                    weaponManager.FireAtAngle(Angle, WeaponType.Gun, this.locationState == LocationState.AirTurningRound, coll);
                }
            }
        }