Exemplo 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);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// obiekt otwiera ogien.
        /// </summary>
        /// <param name="planeAngle">Kat nachylenia samolotu.</param>
        public void FireAtAngle(float fireAngle, WeaponType weaponType, bool isTurningAround, MissileBase.CollisionDirectionLocation fireDirection)
        {
            switch (weaponType)
            {
            case WeaponType.Bomb:
                BombFire();
                break;

            case WeaponType.Gun:
                PlaneFireGun(fireAngle, isTurningAround, fireDirection);
                break;

            case WeaponType.Rocket:
                RocketFire(fireAngle);
                break;

            case WeaponType.Torpedo:
                TorpedoFire();
                break;

            default:
                break;
            }
        }
Exemplo n.º 3
0
        private IList <GunBullet> PlaneFireGun(float angle, bool isTurningAround, MissileBase.CollisionDirectionLocation fireDirection)
        {
            //dzwiek strzalu.
            Plane plane = ammunitionOwner as Plane;

            refToLevel.Controller.OnFireGun(plane);
            IList <GunBullet> bullets = new List <GunBullet>();

            if (Environment.TickCount - lastFireTick >= GameConsts.Gun.FireInterval * 1)
            {
                PlaneView pv       = refToLevel.Controller.FindPlaneView(plane);           // na razie hardkod przez DelayedControllerFacade
                GunBullet bullet   = null;
                PointD    position = null;

                //startowa pozycja pocisku
                position = new PointD(ammunitionOwner.Center.X, ammunitionOwner.Center.Y);


                //nowy pocisk

                Quaternion q = pv.InnerNode._getDerivedOrientation();

                if (fireDirection == MissileBase.CollisionDirectionLocation.FORWARD || fireDirection == MissileBase.CollisionDirectionLocation.BOTH)
                {
                    // forward
                    bullet = new GunBullet(position.X, position.Y, q, refToLevel, ammunitionOwner, false, true);

                    bullet.SetZRotationPerSecond(0.09f);
                    bullets.Add(bullet);

                    refToLevel.Controller.OnRegisterGunBullet(bullet);
                    RegisterWeaponToModelEvent(bullet);
                }

                if (fireDirection == MissileBase.CollisionDirectionLocation.BACKWARD || fireDirection == MissileBase.CollisionDirectionLocation.BOTH)
                {
                    // backward
                    float tailShift = 4.0f;
                    q = q * new Quaternion(new Radian(new Degree(180)), Vector3.UNIT_X);
                    Vector3 displacement = q * new Vector3(0, 0, -tailShift);


                    bullet = new GunBullet(position.X + displacement.x, position.Y + displacement.y, q, refToLevel, ammunitionOwner, true, false);
                    bullet.SetZRotationPerSecond(0.09f);
                    bullets.Add(bullet);
                    RegisterWeaponToModelEvent(bullet);
                    refToLevel.Controller.OnRegisterGunBullet(bullet);
                }

                //zwieksza liczbe uzytych rakiet
                if (!this.ammunitionOwner.IsEnemy && !isTurningAround)
                {
                    this.refToLevel.Statistics.GunCount++;
                    if (fireDirection == MissileBase.CollisionDirectionLocation.BOTH)
                    {
                        this.refToLevel.Statistics.GunCount++;
                    }
                }

                //ustawiam nowy czas
                lastFireTick = Environment.TickCount;

                return(bullets);
            }

            return(null);
        }