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


C# Levels.getAdjacentBlocks方法代码示例

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


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

示例1: collision

        public override void collision(Levels.Level level)
        {
            foreach (Block b in level.Blocks)
            {
                if (Position.Intersects(b.Position))
                {
                    Block final = b;

                    foreach (Block n in level.getAdjacentBlocks(b))
                    {

                        if (Rectangle.Intersect(Position, n.Position).Width * Rectangle.Intersect(Position, n.Position).Height > Rectangle.Intersect(Position, final.Position).Width * Rectangle.Intersect(Position, final.Position).Height)
                            final = n;

                    }
                    if (Rectangle.Intersect(Position, final.Position).Width >= Rectangle.Intersect(Position, final.Position).Height)
                    {

                        if (Rectangle.Intersect(Position, final.Position).Top == final.Position.Top)
                        {
                            Position = new Rectangle(Position.X, final.Position.Top - Position.Height, Position.Width, Position.Height);
                            Velocity = new Vector2(Velocity.X, - 6);
                        }
                        else if (Rectangle.Intersect(Position, final.Position).Bottom == final.Position.Bottom)
                        {
                            Position = new Rectangle(Position.X, final.Position.Bottom, Position.Width, Position.Height);
                            Velocity = new Vector2(Velocity.X, Velocity.Y * -1); ;
                        }
                    }
                    else
                    {

                        if (Rectangle.Intersect(Position, final.Position).Left == final.Position.Left)
                        {
                            Velocity = new Vector2(-1, Velocity.Y);
                            Position = new Rectangle(final.Position.Left - Position.Width, Position.Y, Position.Width, Position.Height);

                        }
                        else if (Rectangle.Intersect(Position, final.Position).Right == final.Position.Right)
                        {
                            Velocity = new Vector2(1, Velocity.Y);
                            Position = new Rectangle(final.Position.Right, Position.Y, Position.Width, Position.Height);
                        }

                    }

                    break;
                }
            }
        }
开发者ID:JohnP42,项目名称:super-luigi,代码行数:50,代码来源:Starman.cs


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