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


C# Room.GetCollidingSolidEntities方法代码示例

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


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

示例1: MoveWithCollision

        public void MoveWithCollision(Room room)
        {
            if (Velocity.X > 0)
            {
                int x = ((position.X + Velocity.X) / Resolution + Width) / room.TileMap.TileSize.X;

                int yStart = Y / room.TileMap.TileSize.Y;
                int yEnd = (Y + Height - 2) / room.TileMap.TileSize.Y;

                for (int y = yStart; y <= yEnd; y++)
                {
                    if (room.TileMap.IsSolid(x, y))
                    {
                        X = x * room.TileMap.TileSize.X - Width;
                        Velocity.X = 0;
                        break;
                    }
                }

                if (Velocity.X != 0)
                {
                    IList<Entity> solids = room.GetCollidingSolidEntities(new Rectangle((position.X + Velocity.X) / Resolution, Y, Width, Height));

                    foreach (Entity s in solids)
                    {
                        if (s == this) continue;

                        X = s.X - Width;
                        Velocity.X = 0;
                    }
                }
            }
            else if (Velocity.X < 0)
            {
                int x = ((position.X + Velocity.X) / Resolution) / room.TileMap.TileSize.X;

                int yStart = Y / room.TileMap.TileSize.Y;
                int yEnd = (Y + Height - 2) / room.TileMap.TileSize.Y;

                for (int y = yStart; y <= yEnd; y++)
                {
                    if (room.TileMap.IsSolid(x, y))
                    {
                        X = (1 + x) * room.TileMap.TileSize.X;
                        Velocity.X = 0;
                        break;
                    }
                }

                if (Velocity.X != 0)
                {
                    IList<Entity> solids = room.GetCollidingSolidEntities(new Rectangle((position.X + Velocity.X) / Resolution, Y, Width, Height));

                    foreach (Entity s in solids)
                    {
                        if (s == this) continue;

                        X = s.X + s.Width;
                        Velocity.X = 0;
                    }
                }
            }

            if (Velocity.Y > 0)
            {
                int y = ((position.Y + Velocity.Y) / Resolution + Height) / room.TileMap.TileSize.Y;

                int xStart = ((position.X + Velocity.X) / Resolution) / room.TileMap.TileSize.X;
                int xEnd = ((position.X + Velocity.X) / Resolution + Width - 1) / room.TileMap.TileSize.X;

                for (int x = xStart; x <= xEnd; x++)
                {
                    if (room.TileMap.IsSolid(x, y))
                    {
                        Y = y * room.TileMap.TileSize.Y - Height;
                        Velocity.Y = 0;
                        break;
                    }
                }

                if (Velocity.Y != 0)
                {
                    IList<Entity> solids = room.GetCollidingSolidEntities(new Rectangle((position.X + Velocity.X) / Resolution, (position.Y + Velocity.Y) / Resolution, Width, Height));

                    foreach (Entity s in solids)
                    {
                        if (s == this) continue;

                        Y = s.Y - Height;
                        Velocity.Y = 0;
                    }
                }
            }
            else if (Velocity.Y < 0)
            {
                int y = ((position.Y + Velocity.Y) / Resolution - 1) / room.TileMap.TileSize.Y;

                int xStart = ((position.X + Velocity.X) / Resolution) / room.TileMap.TileSize.X;
                int xEnd = ((position.X + Velocity.X) / Resolution + Width - 1) / room.TileMap.TileSize.X;

//.........这里部分代码省略.........
开发者ID:weimingtom,项目名称:db-diver,代码行数:101,代码来源:Entity.cs

示例2: IsTileSolidBelow

        public bool IsTileSolidBelow(Room room)
        {
            int y = (Dimension.Y + Dimension.Height) / room.TileMap.TileSize.Y;

            int xStart = Dimension.X / room.TileMap.TileSize.X;
            int xEnd = (Dimension.X + Dimension.Width - 1) / room.TileMap.TileSize.X;

            for (int x = xStart; x <= xEnd; x++)
            {
                if (room.TileMap.IsSolid(x, y))
                {
                    return true;
                }
            }

            IList<Entity> solids = room.GetCollidingSolidEntities(new Rectangle(X, Y + Height, Width, 1));

            return solids.Count > 0 && !(solids.Count == 1 && solids.Contains(this));
        }
开发者ID:weimingtom,项目名称:db-diver,代码行数:19,代码来源:Entity.cs


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