Exemplo n.º 1
0
        public override bool Check(PCar car)
        {
            CollisionRect carRect = new CollisionRect(car);

            List <CollisionInfo> collisions = CollisionDetector.CheckCollision(carRect, collisionObjects);

            if (!collisions.HasCollision())
            {
                return(false);
            }

            foreach (CollisionInfo info in collisions)
            {
                if (!info.CollisionDeletected)
                {
                    continue;
                }

                Vector normal = info.NormalObj1;
                if (car.Dir.Dot(normal) > -1.0e-2)
                {
                    continue;
                }

                checkInfo = new Tuple <Vector, Vector>(info.Point, normal);
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        ///Other
        private List <ICollisionObject> objectsByTilesAndEdgesInfo(Dictionary <TilePos, TileDir[]> tilesInfo)
        {
            CollisionRect carRect = new CollisionRect(car);

            List <ICollisionObject> result = new List <ICollisionObject>();

            if (null != tilesInfo)
            {
                foreach (TilePos pos in tilesInfo.Keys)
                {
                    foreach (TileDir dir in tilesInfo[pos])
                    {
                        ICollisionObject obj = null;
                        if (dir.Correct())
                        {
                            obj = new CollisionSide(pos, dir);
                        }
                        else
                        {
                            obj = new CollisionCircle(pos, dir);
                        }

                        if (null == CollisionDetector.CheckCollision(carRect, obj))
                        {
                            result.Add(obj);
                        }
                    }
                }
            }
            return(result);
        }