Nez.Portable/ECS/Components/Physics/TiledMapMover.cs
/// <summary>
/// gets a list of all the tiles intersecting bounds. The returned list is ordered for collision detection based on the
/// direction passed in so they can be processed in order.
/// </summary>
/// <returns>The colliding tiles.</returns>
/// <param name="bounds">Bounds.</param>
/// <param name="direction">Direction.</param>
gets a list of all the tiles intersecting bounds. The returned list is ordered for collision detection based on the
direction passed in so they can be processed in order.
gets a list of all the tiles intersecting bounds . The returned list is ordered for collision detection based on the direction passed in so they can be processed in order .
void populateCollidingTiles(Rectangle bounds, Edge direction)
        {
            _collidingTiles.Clear();
            var isHorizontal = direction.isHorizontal();
            var primaryAxis = isHorizontal ? Axis.X : Axis.Y;
            var oppositeAxis = primaryAxis == Axis.X ? Axis.Y : Axis.X;
            var oppositeDirection = direction.oppositeEdge();
            var firstPrimary = worldToTilePosition(bounds.getSide(oppositeDirection), primaryAxis);
            var lastPrimary = worldToTilePosition(bounds.getSide(direction), primaryAxis);
            var primaryIncr = direction.isMax() ? 1 : -1;
            var min = worldToTilePosition(isHorizontal ? bounds.Top : bounds.Left, oppositeAxis);
            var mid = worldToTilePosition(isHorizontal ? bounds.getCenter().Y : bounds.getCenter().X, oppositeAxis);
            var max = worldToTilePosition(isHorizontal ? bounds.Bottom : bounds.Right, oppositeAxis);
            var isPositive = mid - min < max - mid;
            var secondaryIncr = isPositive ? 1 : -1;
            var firstSecondary = isPositive ? min : max;
            var lastSecondary = !isPositive ? min : max;
            for (var primary = firstPrimary; primary != lastPrimary + primaryIncr; primary += primaryIncr)
            {
                for (var secondary = firstSecondary;
                     secondary != lastSecondary + secondaryIncr;
                     secondary += secondaryIncr)
                {
                    var col = isHorizontal ? primary : secondary;
                    var row = !isHorizontal ? primary : secondary;
                    _collidingTiles.Add(collisionLayer.getTile(col, row));
#if DEBUG_MOVER
					if( direction.isHorizontal() )
					{
						var pos = tiledMap.tileToWorldPosition( new Point( col, row ) );
						_debugTiles.Add( new Rectangle( (int)pos.X, (int)pos.Y, 16, 16 ) );
					}
					#endif
                }
            }
        }
void populateCollidingTiles ( Rectangle bounds , Edge direction ) { _collidingTiles . Clear ( ) ; var isHorizontal = direction . isHorizontal ( ) ; var primaryAxis = isHorizontal ? Axis . X : Axis . Y ; var oppositeAxis = primaryAxis == Axis . X ? Axis . Y : Axis . X ; var oppositeDirection = direction . oppositeEdge ( ) ; var firstPrimary = worldToTilePosition ( bounds . getSide ( oppositeDirection ) , primaryAxis ) ; var lastPrimary = worldToTilePosition ( bounds . getSide ( direction ) , primaryAxis ) ; var primaryIncr = direction . isMax ( ) ? 1 : - 1 ; var min = worldToTilePosition ( isHorizontal ? bounds . Top : bounds . Left , oppositeAxis ) ; var mid = worldToTilePosition ( isHorizontal ? bounds . getCenter ( ) . Y : bounds . getCenter ( ) . X , oppositeAxis ) ; var max = worldToTilePosition ( isHorizontal ? bounds . Bottom : bounds . Right , oppositeAxis ) ; var isPositive = mid - min < max - mid ; var secondaryIncr = isPositive ? 1 : - 1 ; var firstSecondary = isPositive ? min : max ; var lastSecondary = ! isPositive ? min : max ; for ( var primary = firstPrimary ; primary != lastPrimary + primaryIncr ; primary += primaryIncr ) { for ( var secondary = firstSecondary ; secondary != lastSecondary + secondaryIncr ; secondary += secondaryIncr ) { var col = isHorizontal ? primary : secondary ; var row = ! isHorizontal ? primary : secondary ; _collidingTiles . Add ( collisionLayer . getTile ( col , row ) ) ; if DEBUG_MOVER if ( direction . isHorizontal ( ) ) { var pos = tiledMap . tileToWorldPosition ( new Point ( col , row ) ) ; _debugTiles . Add ( new Rectangle ( ( int ) pos . X , ( int ) pos . Y , 16 , 16 ) ) ; } endif } } }
gets a list of all the tiles intersecting bounds.
gets a list of all the tiles intersecting bounds .
The colliding tiles.
The colliding tiles .
bounds
Rectangle
None
direction
Edge
None