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


C# Box.CheckSuffocation方法代码示例

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


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

示例1: PlaceOrRemoveBlock


//.........这里部分代码省略.........
            return false;
             }

             // adjust the reverse shift by accounting for reverse number truncating
             // when below 0
             if (closest.IntersectionPoint.X < 0 && closest.IntersectionPoint.X % 1 != 0)
             {
            reverseShiftX--;
             }
             if (closest.IntersectionPoint.Z < 0 && closest.IntersectionPoint.Z % 1 != 0)
             {
            reverseShiftZ--;
             }
             // calculate cube location without the shift
             x = Convert.ToInt32(Math.Truncate(closest.IntersectionPoint.X)) + reverseShiftX;
             y = Convert.ToInt32(Math.Truncate(closest.IntersectionPoint.Y));
             z = Convert.ToInt32(Math.Truncate(closest.IntersectionPoint.Z)) + reverseShiftZ;

             if (place)
             {
            // correct the location based on intersection side
            switch (closest.Side)
            {
               case Sides.FrontX:
                  x--;
                  break;
               case Sides.FrontY:
                  y--;
                  break;
               case Sides.FrontZ:
                  z--;
                  break;
            }
             }
             else
             {
            // correct the location based on intersection side
            switch (closest.Side)
            {
               case Sides.BackX:
                  x--;
                  break;
               case Sides.BackY:
                  y--;
                  break;
               case Sides.BackZ:
                  z--;
                  break;
            }
             }

             // check for floor/ceiling limits
             if (y < 0 || y > byte.MaxValue)
             {
            return false;
             }

             // adjust possible shift over the edge of the world after correction
             if (x < 0)
             {
            x += WorldHelper.SizeX;
             }
             else if (x >= WorldHelper.SizeX)
             {
            x -= WorldHelper.SizeX;
             }

             if (z < 0)
             {
            z += WorldHelper.SizeZ;
             }
             else if (z >= WorldHelper.SizeZ)
             {
            z -= WorldHelper.SizeZ;
             }

             // check if placing the block will clip into an entity
             if (place)
             {
            Box box = new Box(new Cube(x, y, z, 0), null);
            List<Entity> entities = WorldHelper.GetEntities(box.CenterPoint, BlockEntityCollisionSelectRange);

            bool collides = false;
            foreach (Entity entity in entities)
            {
               box.CheckSuffocation(entity.Location, ref entity._HalfSizeX, ref entity._HalfSizeY, ref collides);
               if (collides)
               {
                  // at least one entity collides with the newly placed box
                  return false;
               }
            }
             }

             // retrieve the destination segment and place or remove the block
             Segment destinationSegment = WorldHelper.GetSegment(x, y, z);
             version = destinationSegment.PlaceOrRemoveBlockAndUpdateVersion(place, x, y, z, GetSelectedMaterial());

             return true;
        }
开发者ID:daxola123,项目名称:Qbes,代码行数:101,代码来源:Entity.cs


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