Пример #1
0
        /// <summary>
        /// Checks for overlaps between the provided object and any tiles above the collision index.
        /// </summary>
        /// <param name="Core">The <code>FlxObject</code> you want to check against.</param>
        /// <returns>True if overlap occurs, otherwise False</returns>
        override public bool overlaps(FlxObject Core)
        {
            int d;

            int dd;
            List <BlockPoint> blocks = new List <BlockPoint>();

            //First make a list of all the blocks we'll use for collision
            int ix = (int)FlxU.floor((Core.x - x) / _tileWidth);
            int iy = (int)FlxU.floor((Core.y - y) / _tileHeight);
            int iw = (int)FlxU.ceil((float)Core.width / (float)_tileWidth) + 1;
            int ih = (int)FlxU.ceil((float)Core.height / (float)_tileHeight) + 1;
            int r  = 0;
            int c;

            while (r < ih)
            {
                if (r >= heightInTiles)
                {
                    break;
                }
                d = (iy + r) * widthInTiles + ix;
                c = 0;
                while (c < iw)
                {
                    if (c >= widthInTiles)
                    {
                        break;
                    }
                    dd = _data[d + c];
                    if (dd >= collideMin && dd >= collideMax)
                    {
                        blocks.Add(new BlockPoint((int)(x + (ix + c) * _tileWidth), (int)(y + (iy + r) * _tileHeight), dd));
                    }
                    c++;
                }
                r++;
            }

            //Then check for overlaps
            int bl = blocks.Count;
            int i  = 0;

            while (i < bl)
            {
                _block.x = blocks[i].x;
                _block.y = blocks[i++].y;
                if (_block.overlaps(Core))
                {
                    return(true);
                }
            }
            return(false);
        }