示例#1
0
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            if (IsValidName)
            {
                builder.AppendLine("ID: " + id);
            }
            if (IsValidYEnd)
            {
                builder.AppendLine("Y-End: " + yEnd);
            }
            if (IsValidYStart)
            {
                builder.AppendLine("Y-Start: " + yStart);
            }
            if (IsValidViewXShift)
            {
                builder.AppendLine("View-X-Shift: " + viewXShift);
            }
            if (IsValidVariation)
            {
                builder.AppendLine("Variation: " + variation);
            }
            if (IsValidRectangle)
            {
                builder.AppendLine("Ractangle: " + rectangle.ToString());
            }
            if (IsValidHitRectangle)
            {
                builder.AppendLine("Hit rectangle: " + hitRectangle.ToString());
            }

            return(builder.ToString());
        }
        private void RectanglesTestForm_Load(object sender, EventArgs e)
        {
            Quadrangle quadrangle = new Quadrangle(
                new PointD(90, 100),
                new PointD(100, 220),
                new PointD(200, 200),
                new PointD(200, 100));

            Console.WriteLine(quadrangle.ToString());
            tab = quadrangle.ToDrawingTable(ClientRectangle.Height);
        }
示例#3
0
        /// <summary>
        /// Zwraca opis danego elementu.
        /// </summary>
        /// <returns>String.</returns>
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("yBegin: " + yBegin);
            builder.AppendLine("yEnd: " + yEnd);
            if (hitBound != null)
            {
                builder.AppendLine("Hit bound: " + hitBound.ToString());
            }

            return(builder.ToString());
        }
示例#4
0
        /*public static void Main()
         * {
         *  TestCompare();
         * }*/

        public static void TestCompare()
        {
            Quadrangle quad = new Quadrangle(
                new PointD(0, 1),
                new PointD(0, 0),
                new PointD(1, 0),
                new PointD(1, 1));

            Console.WriteLine(quad.ToString());
            quad = new Quadrangle(new PointD(5, 2),
                                  new PointD(7, 8),
                                  new PointD(9, 6),
                                  new PointD(3, 4));
            Console.WriteLine(quad.ToString());
        }
示例#5
0
文件: Gun.cs 项目: havri/ActionGame
        /// <summary>
        /// Performes the bullet releasing in the shoot process
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="position">Start position</param>
        /// <param name="azimuth">Flight direction</param>
        /// <param name="visualiseBullet">Whether the bullet should be visualised indicator</param>
        /// <returns>True if the bullet hit something</returns>
        bool PerformShoot(GameTime gameTime, PositionInTown position, float azimuth, bool visualiseBullet)
        {
            const float bulletWidth = 0.02f;
            //const float startHeight = 0.5f;
            const float bulletWidthHalf = bulletWidth / 2;

            bool   solveHeight = (Holder is Player);
            double lookAngle   = Holder.LookAngle;
            //Vector2 quarterPosition = position.PositionInQuarter;
            float       startHeight     = Holder.FirstHeadPosition.Y - bulletWidth;
            Vector2     quarterPosition = position.PositionInQuarter;
            Vector2     left            = quarterPosition.Go(bulletWidthHalf, azimuth - MathHelper.PiOver2);
            Vector2     right           = quarterPosition.Go(bulletWidthHalf, azimuth + MathHelper.PiOver2);
            Quadrangle  bullet          = new Quadrangle(right, left, right.Go(type.Range, azimuth), left.Go(type.Range, azimuth));
            TownQuarter quarter         = position.Quarter;

            List <Quadrangle> colliders = new List <Quadrangle>(quarter.SpaceGrid.GetAllCollisions(bullet));

            colliders.RemoveAll(x => x == Holder);

            //Half-interval search
            Stack <RangeF>            testedParts = new Stack <RangeF>();
            Dictionary <float, float> heights     = new Dictionary <float, float>();

            testedParts.Push(new RangeF(0, type.Range));
            if (solveHeight)
            {
                heights.Add(0, startHeight);
                heights.Add(type.Range, startHeight + type.Range * (float)Math.Tan(lookAngle));
            }

            Quadrangle nearest  = null;
            float      distance = type.Range;

            while (testedParts.Count != 0)
            {
                RangeF bulletRangePart = testedParts.Pop();
                float  h1 = 0f;
                float  h2 = 0f;
                if (solveHeight)
                {
                    h1 = heights[bulletRangePart.Begin];
                    h2 = heights[bulletRangePart.End];
                }
                Quadrangle bulletPart = new Quadrangle(
                    left.Go(bulletRangePart.Begin, azimuth),
                    right.Go(bulletRangePart.Begin, azimuth),
                    left.Go(bulletRangePart.End, azimuth),
                    right.Go(bulletRangePart.End, azimuth));
                List <Quadrangle> newColliders = new List <Quadrangle>(
                    colliders.Where(
                        x =>
                        (solveHeight && x is SpatialObject && (((SpatialObject)x).Size.Y >= h2 || ((SpatialObject)x).Size.Y >= h2) && (0 <= h1 || 0 <= h2) && x.IsInCollisionWith(bulletPart))
                        ||
                        (!solveHeight && x.IsInCollisionWith(bulletPart))
                        )
                    );
                if (newColliders.Count != 0)
                {
                    if (newColliders.Count == 1 || bulletRangePart.Length <= bulletWidthHalf)
                    {
                        nearest  = newColliders[0];
                        distance = bulletRangePart.End;
                        break;
                    }
                    colliders = newColliders;
                    float halfLength = bulletRangePart.Length * 0.5f;
                    float middle     = bulletRangePart.Begin + halfLength;
                    testedParts.Push(new RangeF(middle, bulletRangePart.End));
                    testedParts.Push(new RangeF(bulletRangePart.Begin, middle));
                    if (solveHeight && halfLength != 0f)
                    {
                        heights.Add(middle, startHeight + middle * (float)Math.Tan(lookAngle));
                    }
                }
            }


            if (visualiseBullet)
            {
                quarter.AddBullet(gameTime, new BulletVisualisation(quarter, quarterPosition, azimuth, distance, startHeight, startHeight + distance * (float)Math.Tan(lookAngle)));
            }
            if (nearest != null)
            {
                Debug.Write("Shot", nearest.ToString());
                nearest.BecomeShoot(gameTime, type.Damage, Holder);
                return(true);
            }
            return(false);
        }