コード例 #1
0
        private void IntersectionTestForm_KeyDown(object sender, KeyEventArgs e)
        {
            const float angle        = Math.PI / 36.0f;
            PointD      rotateCenter = new PointD(200, 300);

            switch (e.KeyCode)
            {
            case Keys.Up:
                activeQ.Move(0, Step);
                break;

            case Keys.Down:
                activeQ.Move(0, -Step);
                break;

            case Keys.Left:
                activeQ.Move(-Step, 0);
                break;

            case Keys.Right:
                activeQ.Move(Step, 0);
                break;

            case Keys.NumPad8:
                activeQ.Rotate(angle);
                break;

            case Keys.NumPad2:
                activeQ.Rotate(-angle);
                break;

            case Keys.B:
                activeQ = q1;
                break;

            case Keys.G:
                activeQ = q2;
                break;

            case Keys.NumPad9:
                activeQ.Move(Step, Step);
                break;

            //case ' ': MessageBox.Show(q1.ToString()); break;
            default:
                break;
            }
            pictureBox1.Refresh();
            if (q1.Intersects(q2))
            {
                Text = "BUM";
            }
            else
            {
                Text = "";
            }
        }
コード例 #2
0
ファイル: MissileBase.cs プロジェクト: wof2/Wings-Of-Fury-2
        /// <summary>
        /// Funkcja sprawdza czy samolot bedzie mogl trafic rakieta w inny obiekt.
        /// </summary>
        /// <param name="plane">Samolot strzelajacy.</param>
        /// <param name="enemyPlane">Samolot, ktory chemy trafic.</param>
        /// <returns>Zwraca true jesli moze trafic wrogi samolot; false - w przeciwnym
        /// przypadku.</returns>
        /// <author>Michal Ziober</author>
        public static CollisionDirectionLocation CanHitEnemyPlane(Plane plane, Plane enemyPlane, float tolerance, bool biDirectional)
        {
            if (!biDirectional)
            {
                if (plane.Direction == Direction.Right && plane.Center.X > enemyPlane.Center.X)
                {
                    return(CollisionDirectionLocation.NONE);
                }

                if (plane.Direction == Direction.Left && plane.Center.X < enemyPlane.Center.X)
                {
                    return(CollisionDirectionLocation.NONE);
                }
            }

            if (System.Math.Abs(plane.Center.X - enemyPlane.Center.X) < 10 &&
                System.Math.Abs(plane.Center.Y - enemyPlane.Center.Y) < 10)
            {
                return(CollisionDirectionLocation.NONE);
            }

            if (System.Math.Abs((plane.Center - enemyPlane.Center).EuclidesLength) > ViewRange)
            {
                return(CollisionDirectionLocation.NONE);
            }

            Quadrangle planeQuad = new Quadrangle(plane.Bounds.Peaks);

            planeQuad.Move(0, -HeightShift);
            Line lineA = new Line(planeQuad.Peaks[1], planeQuad.Peaks[2]);

            for (int i = 0; i < enemyPlane.Bounds.Peaks.Count - 1; i++)
            {
                PointD start = enemyPlane.Bounds.Peaks[i];
                start += new PointD(Math.RangeRandom(-tolerance * 0.5f, -tolerance * 0.5f), Math.RangeRandom(-tolerance * 0.5f, -tolerance * 0.5f));

                PointD finish = enemyPlane.Bounds.Peaks[i + 1];
                finish += new PointD(Math.RangeRandom(-tolerance * 0.5f, -tolerance * 0.5f), Math.RangeRandom(-tolerance * 0.5f, -tolerance * 0.5f));

                Line lineB = new Line(start, finish);



                PointD cut = lineA.Intersect(lineB);
                if (cut == null)
                {
                    continue;
                }

                if ((enemyPlane.Center - cut).EuclidesLength < HitShift)
                {
                    //ViewHelper.AttachCross(plane.Level.Controller.GetFramework().SceneMgr, cut, 10);
                    //return true;

                    return((plane.Direction == Direction.Right && plane.Center.X > enemyPlane.Center.X || plane.Direction == Direction.Left && plane.Center.X < enemyPlane.Center.X) ? CollisionDirectionLocation.BACKWARD : CollisionDirectionLocation.FORWARD);
                }
            }

            return(CollisionDirectionLocation.NONE);
        }
コード例 #3
0
        private void IntersectionTestForm_KeyDown(object sender, KeyEventArgs e)
        {
            const float angle = Math.PI / 36.0f;

            //     PointD rotateCenter = new PointD(300, 300);
            switch (e.KeyCode)
            {
            case Keys.Up:
                activeQ.Move(0, Step);
                break;

            case Keys.Down:
                activeQ.Move(0, -Step);
                break;

            case Keys.Left:
                activeQ.Move(-Step, 0);
                break;

            case Keys.Right:
                activeQ.Move(Step, 0);
                break;

            case Keys.NumPad8:
                activeQ.Rotate(angle);
                break;

            case Keys.NumPad2:
                activeQ.Rotate(-angle);
                break;

            case Keys.B:
                activeQ = plane1.Bounds;
                break;

            case Keys.G:
                activeQ = plane2.Bounds;
                break;

            case Keys.NumPad9:
                activeQ.Move(Step, Step);
                break;

            //case ' ': MessageBox.Show(q1.ToString()); break;
            default:
                break;
            }

            string app = "";

            if (activeQ.IsObverse)
            {
                //   app = " LEFT";
                //   plane1.Direction = Direction.Left;
            }
            else
            {
                //  app = " RIGHT";
                //     plane1.Direction = Direction.Right;
            }

            pictureBox1.Refresh();

            //if (Gun.CanHitObjectByGun(plane1, plane2))
            //    Text = "BUM";
            // else
            //     Text = "";
            Text += app;
        }