Ejemplo n.º 1
0
 /// <summary>
 /// Return a position that is both on the line and in the polygon.
 /// </summary>
 /// <param name="testProjectile"></param>
 /// <param name="part"></param>
 /// <returns></returns>
 internal static CCPoint CollisionPosLinePoly(CollisionTypeLine cTypeLine, ICollidible polyCollidible)
 {
     // for performance reasons first check the bounding box (skip for now because we assume a collision is present
     if (CollideBoundingBoxLine(polyCollidible, cTypeLine))
     {
         // transform the polygon to match the positioning, rotation and scale of the node
         Polygon transformedPolygon = ((Polygon)((CollisionTypePolygon)polyCollidible.CollisionType).collisionPolygon.Clone());
         transformedPolygon.TransformAccordingToGameObject(polyCollidible);
         // first check if the polygon contains some of the two line points
         if (transformedPolygon.ContainsPoint(cTypeLine.StartPoint))
         {
             return(cTypeLine.StartPoint);
         }
         else if (transformedPolygon.ContainsPoint(cTypeLine.EndPoint))
         {
             return(cTypeLine.EndPoint);
         }
         // solve exactly: check for line intersections
         var polyPoints = transformedPolygon.Points;
         int i, j;
         for (i = 0, j = polyPoints.Length - 1; i < polyPoints.Length; j = i++)
         {
             if (CCPoint.SegmentIntersect(cTypeLine.StartPoint, cTypeLine.EndPoint, polyPoints[i], polyPoints[j]))
             {
                 return(CCPoint.IntersectPoint(cTypeLine.StartPoint, cTypeLine.EndPoint, polyPoints[i], polyPoints[j]));
             }
         }
     }
     return(CCPoint.Zero);
 }
Ejemplo n.º 2
0
        internal static bool CollideLineLineAt(CCPoint start1, CCPoint end1, CCPoint start2, CCPoint end2, out float cX, out float cY)
        {
            var point = CCPoint.IntersectPoint(start1, end1, start2, end2);

            cX = point.X; cY = point.Y;
            if (CCPoint.SegmentIntersect(start1, end1, start2, end2))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        private EnemyBullet AddEnemyBullet(CCSprite sender)
        {
            EnemyBullet bullet = new EnemyBullet();

            bullet.Position = new CCPoint(sender.Position.X, sender.Position.Y - sender.ContentSize.Height / 2);
            AddChild(bullet, ENEMY_BULLET_INDEX);

            CCPoint target   = CCPoint.IntersectPoint(bullet.Position, player.Position, CCPoint.Zero, new CCPoint(VisibleBoundsWorldspace.MaxX, 0));
            float   distance = CCPoint.Distance(bullet.Position, target);

            var moveBullet = new CCMoveTo(distance / ENEMY_BULLET_SPEED, target);

            bullet.RunActions(moveBullet, moveOutOfView);
            return(bullet);
        }