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


C# ICollidable.Collide方法代码示例

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


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

示例1: TryWalk

        public bool TryWalk(Vector2 rel, ICollidable collision)
        {
            int tries = -walkSlope;
            while (collision.Collide(new Rectangle(Bounds.X + (int)Math.Round(rel.X * (walkSlope - tries) / walkSlope), Bounds.Y + (int)Math.Round(rel.Y) - tries, Bounds.Width, Bounds.Height)) &&
                tries < walkSlope)
            {
                tries++;
            }
            if (tries == walkSlope)
            {
                return false;
            }
            if (tries == -walkSlope)
            {
                Grounded = false;
                move(rel);
                return true;
            }

            move(rel * new Vector2((walkSlope - tries) / walkSlope, 1) - Vector2.UnitY * tries);
            return true;
        }
开发者ID:KennethE,项目名称:KennethKode,代码行数:22,代码来源:Player.cs

示例2: TryMove

        public bool TryMove(Vector2 rel, ICollidable collision)
        {
            if (collision.Collide(new Rectangle(Bounds.X + (int)Math.Round(rel.X), Bounds.Y + (int)Math.Round(rel.Y), Bounds.Width, Bounds.Height)))
            {
                return false;
            }

            move(rel);
            return true;
        }
开发者ID:KennethE,项目名称:KennethKode,代码行数:10,代码来源:Player.cs

示例3: TestCollision


//.........这里部分代码省略.........
                finalResult.minimumTranslationVector = o.Velocity * frameTime;
                finalResult.frameTime = frameTime;
                int finalNormalOwner = -1;

                //Check each edge
                foreach (BoundingPolygon p in polygons)
                {
                    /*if (p.Vertices.Count == 2 && p.EdgeNormals[0].DotProduct(o.Velocity) > 0)
                    {
                        #if DEBUG_COLLISION_OBJECT_POLYGON
                        Log.Write("Polygon has only one edge, which faces the same way as the movement direction. Ignoring.", Log.DEBUG);
                        #endif
                        continue;
                    }*/

                    #if DEBUG_COLLISION_OBJECT_POLYGON
                    Log.Write("Object bounding polygon: " + o.BoundingBox, Log.DEBUG);
                    Log.Write("Testing polygon " + p, Log.DEBUG);
                    #endif

                    //Collision results for the current polygon
                    CollisionResult result = new CollisionResult();
                    edges[1] = p.EdgeNormals;

                    bool separating = false;
                    int normalOwner = -1;

                    for (int i = 0; i < edges.Length; i++)
                    {
                        var poly = edges[i];
                        foreach (Vector axis in poly)
                        {
                            // Do the collision test on the polygons
                            testAxis(ProjectPolygon(oldBoundingBox, axis), ProjectPolygon(p, axis), velocity, axis, result, remainingFrameTime, i);
                            if (object.ReferenceEquals(axis, result.hitNormal))
                                normalOwner = i;

                            if (!result.hasIntersected && !result.isIntersecting)
                            {
                                separating =  true;
                                break;
                            }
                            if (result.isIntersecting && double.IsNegativeInfinity(result.distance)) result.isIntersecting = false;
                        }
                        if (separating) break;
                    }

                    //Already intersecting
                    if (result.isIntersecting)
                    {
                        finalResult = result;
                        finalNormalOwner = normalOwner;
                        minimumCollisionTime = 0;
                        firstCollisionPolygon = p;
                    }
                    //Will intersect with p in the future.
                    //If we're not already overlapping with another polygon, go ahead and update the current minimum collision time.
                    else if (result.hasIntersected)
                    {
                        //If the collision time is the smallest so far,
                        if (result.collisionTime < minimumCollisionTime)
                        {
                            minimumCollisionTime = result.collisionTime;
                            finalResult = result;
                            finalNormalOwner = normalOwner;
                            firstCollisionPolygon = p;
                        }
                    }
                }

                //If we have a first collision, call the collision handler
                if (firstCollisionPolygon != null)
                {
                    if (finalResult.isIntersecting)
                        finalResult.minimumTranslationVector = (finalNormalOwner == 0 ? 1 : -1) * Math.Abs(finalResult.distance) * finalResult.hitNormal; //o.Velocity * finalResult.distance * frameTime;

                    remainingFrameTime -= minimumCollisionTime;

                    //Subtract a small amount to behave correctly when we have small rounding errors.
                    finalResult.collisionTime = minimumCollisionTime; // - 1e-6;//Constants.MinDouble;

                    o.Collide(firstCollisionPolygon, finalNormalOwner == 1 ? finalResult.hitNormal : -finalResult.hitNormal, finalResult);
                    #if DEBUG_COLLISION_OBJECT_POLYGON
                    Log.Write("COLLISION." + " Time: " + finalResult.collisionTime + " Normal: " + finalResult.hitNormal + " Remaining: " + remainingFrameTime + " Collision polygon: " + firstCollisionPolygon + " Velocity: " + o.Velocity + " Translation vector: " + finalResult.minimumTranslationVector, Log.DEBUG);
                    collCount++;
                    #endif
                }
                else
                {
                    remainingFrameTime = 0;
                    #if DEBUG_COLLISION_OBJECT_POLYGON
                    Log.Write("NO COLLISION.", Log.DEBUG);
                    #endif
                }
            }

            #if DEBUG_COLLISION_OBJECT_POLYGON
            Log.Write("Collision count: " + collCount + "\n", Log.DEBUG);
            #endif
        }
开发者ID:hallgeirl,项目名称:Hiage,代码行数:101,代码来源:CollisionManager.cs

示例4: CheckCollisions

        private void CheckCollisions(double ElapsedTime, List<ICollidable> Objects)
        {
            QTree.Clear();
            for (int i = 0; i < Objects.Count; i++)
                QTree.Add(Objects[i]);
            QTree.CheckCollisions();

            PairList<ICollidable> Collisions = QTree.GetCollisions();
            for (int i = 0; i < Collisions.Count; i++)
            {
                ObjA = Collisions.Get(i).Get(0);
                ObjB = Collisions.Get(i).Get(1);

                ObjA.Collide(ObjB);
                ObjB.Collide(ObjA);

                //Collisions.Get(i).Get(0).Collide(Collisions.Get(i).Get(1));
                //Collisions.Get(i).Get(1).Collide(Collisions.Get(i).Get(0));
            }
        }
开发者ID:DJSymBiotiX,项目名称:MX-Engine,代码行数:20,代码来源:PhysicsEngine.cs

示例5: SubCollided

        /// Return all components are collided with specified components
        /// </summary>
        /// <param name="cp">Component to check collide</param>
        /// <returns>
        /// This collision detect with sub-nodes only
        /// </returns>
        public List<ICollidable> SubCollided(ICollidable cp, List<ICollidable> collided)
        {
            //list of component found
            foreach (CollisionQuadTreeNode node in this.SubNodes)
            {
                if (node.IsEmpty)
                    continue;

                //Case 1: if cp completely be contained in sub-node
                //Go down checking
                if (cp.IsContained(node.Bound))
                {
                    collided.AddRange(node.SubCollided(cp, collided));
                    break;
                }

                //Case 2: if cp intersect with sub-node
                //Check in this node and continue search with other nodes
                if (cp.Intersects(node.Bound))
                {
                    foreach (ICollidable ccp in node.NodeContents)
                    {
                        if (cp.Collide(ccp) || (ccp.Collide(cp)))
                            collided.Add(ccp);
                    }

                    collided.AddRange(node.SubCollided(cp, collided));
                }
            }

            return collided;
        }
开发者ID:doanhtdpl,项目名称:pvz-the-birds,代码行数:38,代码来源:QuadTree.cs


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