当前位置: 首页>>代码示例>>C#>>正文


C# Rectangle.Side方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Rectangle.Side方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.Side方法的具体用法?C# Rectangle.Side怎么用?C# Rectangle.Side使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Rectangle的用法示例。


在下文中一共展示了Rectangle.Side方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestMapStickyCollision

 CollisionInfo? TestMapStickyCollision(Map map, Rectangle rectangle,
     TileInfo.SideType direction, BitArray maybeGroundTile)
 {
     List<CollisionTile> tiles = map.GetCollidingTiles(rectangle, direction);
     for (int i = 0; i < tiles.Count; i++)
     {
         TileInfo.SideType side = TileInfo.OppositeSide(direction);
         GameUnit perpendicularPosition;
         if (TileInfo.Vertical(side))
         {
             perpendicularPosition = rectangle.Center.X;
         }
         else
         {
             perpendicularPosition = rectangle.Center.Y;
         }
         GameUnit leadingPosition = rectangle.Side(direction);
         bool shouldTestSlopes = TileInfo.Vertical(side);
         TestCollisionInfo testInfo = tiles[i].TestCollision(side, perpendicularPosition,
             leadingPosition, shouldTestSlopes);
         if (testInfo.isColliding)
         {
             CollisionInfo info = new CollisionInfo(testInfo.position, tiles[i].Position, tiles[i].TileType);
             return info;
         }
         else if (maybeGroundTile != null && direction == TileInfo.SideType.BottomSide)
         {
             BitArray tallSlope = TileInfo.CreateTileType();
             tallSlope.Set((int)TileInfo.TileFlag.Slope, true);
             tallSlope.Set((int)TileInfo.TileFlag.TallSlope, true);
             if ((maybeGroundTile[(int)TileInfo.TileFlag.Slope] && tiles[i].TileType[(int)TileInfo.TileFlag.Slope]) ||
                 (maybeGroundTile[(int)TileInfo.TileFlag.Wall] &&
                 (tallSlope.And(tiles[i].TileType).Equals(tallSlope))))
             {
                 CollisionInfo info = new CollisionInfo(testInfo.position, tiles[i].Position, tiles[i].TileType);
                 return info;
             }
         }
     }
     return null;
 }
开发者ID:coler706,项目名称:CaveStory,代码行数:41,代码来源:MapCollidable.cs

示例2: TestMapBouncingCollision

 CollisionInfo? TestMapBouncingCollision(Map map, Rectangle rectangle,
     TileInfo.SideType direction, BitArray maybeGroundTile)
 {
     List<CollisionTile> tiles = map.GetCollidingTiles(rectangle, direction);
     CollisionInfo? result = null;
     for (int i = 0; i < tiles.Count; i++)
     {
         TileInfo.SideType side = TileInfo.OppositeSide(direction);
         GameUnit perpendicularPosition;
         if (TileInfo.Vertical(side))
         {
             perpendicularPosition = rectangle.Center.X;
         }
         else
         {
             perpendicularPosition = rectangle.Center.Y;
         }
         GameUnit leadingPosition = rectangle.Side(direction);
         bool shouldTestSlopes = TileInfo.Vertical(side);
         TestCollisionInfo testInfo = tiles[i].TestCollision(side, perpendicularPosition,
             leadingPosition, shouldTestSlopes);
         if (testInfo.isColliding)
         {
             bool shouldReplaceResult = true;
             if (result.HasValue)
             {
                 shouldReplaceResult = TileInfo.IsMin(side) ?
                     testInfo.position < result.Value.position :
                     testInfo.position > result.Value.position;
             }
             if (shouldReplaceResult)
             {
                 CollisionInfo info = new CollisionInfo(testInfo.position, tiles[i].Position, tiles[i].TileType);
                 result = info;
             }
         }
     }
     return result;
 }
开发者ID:coler706,项目名称:CaveStory,代码行数:39,代码来源:MapCollidable.cs

示例3: GetCollidingTiles

        public List<CollisionTile> GetCollidingTiles(Rectangle rectangle, TileInfo.SideType direction)
        {
            TileUnit firstPrimary = Units.GameToTile(rectangle.Side(TileInfo.OppositeSide(direction)));
            TileUnit lastPrimary = Units.GameToTile(rectangle.Side(direction));
            int primaryIncr = TileInfo.IsMax(direction) ? 1 : -1;

            bool horizontal = TileInfo.Horizontal(direction);
            TileUnit sMin = Units.GameToTile(horizontal ? rectangle.Top : rectangle.Left);
            TileUnit sMid = Units.GameToTile(horizontal ? rectangle.Center.Y : rectangle.Center.X);
            TileUnit sMax = Units.GameToTile(horizontal ? rectangle.Bottom : rectangle.Right);

            bool sPositive = sMid - sMin < sMax - sMid;
            int secondaryIncr = sPositive ? 1 : -1;
            TileUnit firstSecondary = sPositive ? sMin : sMax;
            TileUnit lastSecondary = sPositive ? sMin : sMax;
            List<CollisionTile> collisionTiles = new List<CollisionTile>();
            for (TileUnit primary = firstPrimary; primary != lastPrimary + primaryIncr; primary = Convert.ToUInt32(Convert.ToInt32(primary) + primaryIncr))
            {
                for (TileUnit secondary = firstSecondary; secondary != lastSecondary + secondaryIncr; secondary = Convert.ToUInt32(Convert.ToInt32(secondary) + secondaryIncr))
                {
                    TileUnit row = !horizontal ? primary : secondary;
                    TileUnit col = horizontal ? primary : secondary;
                    collisionTiles.Add(new CollisionTile(row, col, tiles[Convert.ToInt32(row)][Convert.ToInt32(col)].tileType));
                }
            }
            return collisionTiles;
        }
开发者ID:coler706,项目名称:CaveStory,代码行数:27,代码来源:Map.cs


注:本文中的Microsoft.Xna.Framework.Rectangle.Side方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。