Example #1
0
        /// <summary>
        /// Zmienia pozycje rakiety.
        /// </summary>
        /// <param name="time">Czas od ostatniego przesuniecia.</param>
        /// <author>Michal Ziober</author>
        protected virtual void ChangePosition(int time)
        {
            float coefficient = Mathematics.GetMoveFactor(time, MoveInterval);

            timeCounter += time;
            if (timeCounter <= dropTime) //swobodne spadanie
            {
                PointD vector = new PointD(moveVector.X * coefficient * 6, moveVector.Y * coefficient);
                boundRectangle.Move(vector);
            }
            else //naped silnikowy
            {
                // Console.WriteLine(flyVector.X);

                float minFlyingSpeed = Owner.IsEnemy ? GameConsts.EnemyFighter.Singleton.RangeFastWheelingMaxSpeed * GameConsts.EnemyFighter.Singleton.MaxSpeed : GameConsts.GenericPlane.CurrentUserPlane.RangeFastWheelingMaxSpeed * GameConsts.GenericPlane.CurrentUserPlane.MaxSpeed;


                // rakieta wytraca prędkość uzyskaną od samolotu
                if (Math.Abs(flyVector.X) > Math.Abs(minFlyingSpeed * GameConsts.Rocket.BaseSpeed))
                {
                    flyVector.X *= 0.995f;
                }

                if (Math.Abs(flyVector.Y) > Math.Abs(minFlyingSpeed * GameConsts.Rocket.BaseSpeed))
                {
                    flyVector.Y *= 0.995f;
                }

                float angle = zRotationPerSecond * coefficient;
                //  boundRectangle.Rotate(angle);
                //  moveVector.Rotate(PointD.ZERO, angle);
                relativeAngle += angle * (int)Direction;
                flyVector.Rotate(PointD.ZERO, angle);

                PointD vector = new PointD(flyVector.X * coefficient, flyVector.Y * coefficient);
                boundRectangle.Move(vector);
                travelledDistance += vector.EuclidesLength;
            }
        }
Example #2
0
        /// <summary>
        /// Ustawia kat dzialka.
        /// </summary>
        /// <author>Michal Ziober</author>
        protected virtual void SetAngle(int time)
        {
            float interval = refToLevel.UserPlane.Center.X;

            if (horizon != null)
            {
                interval -= horizon.Center.X + GetGunXShift();
            }

            //pionowo nad ziemia
            if (interval == 0)
            {
                angle = NinetyDegree;
            }

            float evaluateAngle = 0;

            if (interval < 0)
            {
                evaluateAngle = Math.PI - Math.ATan(refToLevel.UserPlane.Center.Y / Math.Abs(interval)).ValueRadians;
            }
            else
            {
                evaluateAngle = Math.ATan(refToLevel.UserPlane.Center.Y / interval).ValueRadians;
            }

            //Ustawiam kat.
            angle = System.Math.Min(MaxAngle, System.Math.Max(evaluateAngle, MinAngle));

            //  Console.WriteLine("Kat:" +angle+ " "+(angle / (Math.PI)));
            //Ustawiam kat reflectora
            if (UsingReflector)
            {
                SetReflectorAngle(time);
            }
        }
Example #3
0
        /// <summary>
        /// Sprawdza kolizje z ziemia.
        /// </summary>
        /// <param name="planeBound">Prostokat opisujacy samolot.</param>
        /// <param name="position">Pozycja samolotu.</param>
        /// <param name="direction">Kierunek lotu samolotu</param>
        /// <returns>Zwraca punkt zderzenia pocisku z nawierzchnia.</returns>
        /// <author>Adam Witczak</author>
        public PointD GetHitPosition(Quadrangle planeBound, PointD position, Direction direction)
        {
            // czy trafienie bedzie po prawej od samolotu czy po lewej
            Direction hitDirection;

            if (Math.Abs(planeBound.Angle) < Mogre.Math.HALF_PI)
            {
                hitDirection = Direction.Left;
            }
            else
            {
                hitDirection = Direction.Right;
            }

            if (direction == Direction.Right)
            {
                if (hitDirection == Direction.Left)
                {
                    hitDirection = Direction.Right;
                }
                else
                {
                    hitDirection = Direction.Left;
                }
            }

            LevelTile tile;
            int       startIndex;
            int       maxIndex;

            if (hitDirection == Direction.Left)
            {
                maxIndex   = GetStartIndex(position.X);
                startIndex = System.Math.Max(0, maxIndex - 12);
            }
            else
            {
                startIndex = GetStartIndex(position.X);
                maxIndex   = startIndex + 12;
            }

            for (int i = startIndex; i < maxIndex && i < referenceToLevel.LevelTiles.Count; i++)
            {
                // przeszukaj 12 tile'ów do przodu
                tile = referenceToLevel.LevelTiles[i];
                if (tile.HitBound != null)
                {
                    Line   lineA = new Line(tile.HitBound.Peaks[1], tile.HitBound.Peaks[2]);
                    Line   lineB = new Line(planeBound.Peaks[0], planeBound.Peaks[3]);
                    PointD cut   = lineA.Intersect(lineB);
                    if (cut == null)
                    {
                        continue;
                    }
                    if (cut.X > tile.HitBound.Peaks[2].X || cut.X < tile.HitBound.Peaks[1].X)
                    {
                        continue;                                                                       // sytuacja gdy samolot strzela dalej, za tile'em (czyli de facto kula uderzy³aby gdzies dalej mimo ze jest 'intersection' z prost¹)
                    }
                    if (IsCutInRangeX(cut, planeBound.Center))
                    {
                        return(cut);
                    }
                }
            }
            return(null);
        }