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


C# Pawn.OnCollisionExit方法代码示例

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


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

示例1: SetPawnPosition


//.........这里部分代码省略.........
            List<HashSet<Pawn>> toAdd = new List<HashSet<Pawn>>();

            HashSet<Pawn> enterCollisions = new HashSet<Pawn>();
            HashSet<Pawn> exitCollisions = new HashSet<Pawn>();

            Point oldPoint;
            Point newPoint;
            bool walled = false;

            // Gather all pawns that were in the original and new position's footprint
            foreach (Point offset in pawn.Footprint) {
                HashSet<Pawn> oldBucket;
                HashSet<Pawn> newBucket;

                oldPoint = pawn.Position + offset;
                newPoint = newPosition + offset;

                // Check if there's a wall at the new point.  If so, early out.
                if (pawn.IsSolid) {
                    if (InBounds(newPoint) && GetTile(newPoint) == WALL_TILE) {
                        return false;
                    }
                }

                // Add all pawns in the current bucket to the exit collision set
                oldBucket = GetBucket(oldPoint, false);
                if (oldBucket != null) {
                    exitCollisions.UnionWith(oldBucket);
                    toRemove.Add(oldBucket);
                }

                // Add all pawns in the new position to the enter set
                newBucket = GetBucket(newPoint, true);
                enterCollisions.UnionWith(newBucket);
                toAdd.Add(newBucket);
            }

            // If the pawn is solid, and any of the entering collision pawns are solid, don't allow the move
            bool willMove = true;
            if (pawn.IsSolid) {
                if (walled) {
                    willMove = false;
                } else {
                    foreach (Pawn other in enterCollisions) {
                        if (other != pawn && other.IsSolid) {
                            willMove = false;
                            break;
                        }
                    }
                }
            }

            // Move the pawn between buckets
            if (willMove) {
                for (int i = 0; i < toRemove.Count; i++) {
                    toRemove[i].Remove(pawn);
                }

                for (int i = 0; i < toAdd.Count; i++) {
                    toAdd[i].Add(pawn);
                }

                pawn.SetPositionInternal(newPosition);
                moved = true;
            }

            if (pawn.IsCollidable) {
                // The stay set consists of pawns that are in both the exit and enter sets
                HashSet<Pawn> stayCollisions = new HashSet<Pawn>(exitCollisions);
                stayCollisions.IntersectWith(enterCollisions);

                // Remove the stay collisions from both the exit and enter sets
                enterCollisions.ExceptWith(stayCollisions);
                exitCollisions.ExceptWith(stayCollisions);

                // Call the collision methods
                foreach (Pawn other in enterCollisions) {
                    if (pawn != other && other.IsCollidable) {
                        pawn.OnCollisionEnter(other);
                        other.OnCollisionEnter(pawn);
                    }
                }

                foreach (Pawn other in stayCollisions) {
                    if (pawn != other && other.IsCollidable) {
                        pawn.OnCollisionStay(other);
                        other.OnCollisionStay(pawn);
                    }
                }

                foreach (Pawn other in exitCollisions) {
                    if (pawn != other && other.IsCollidable) {
                        pawn.OnCollisionExit(other);
                        other.OnCollisionExit(pawn);
                    }
                }
            }

            return moved;
        }
开发者ID:RolandMQuiros,项目名称:Lost-Generation,代码行数:101,代码来源:Board.cs


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