} // end of function Update()

        private void CheckCollisionWithBlockList()
        {
            PointF nextPos = new PointF();

            nextPos.X = position.X + velocity.X;
            nextPos.Y = position.Y + velocity.Y;

            #region works ok, but does overlap some
            for (int i = 0; i < blockList.Count; i++)
            {
                Blockv0d1 temp = blockList[i];
                if (DistanceBetween(temp.center, position) < temp.size.Width * 2.3 + radius)
                {
                    for (int j = 0; j < blockList[i].ccMarkerList.Count; j++)
                    {
                        if (DistanceBetween(position, blockList[i].ccMarkerList[j].position) <= radius * 1.2)
                        {
                            //IsLaunched = false;
                            SetRectangleCollisionSide(blockList[i]);
                            BounceV3();
                        }
                    }
                }
            }
            #endregion works ok, but does overlap some

            #region works pretty good, but leaves a lot of open space
            //for(int i = 0; i < blockList.Count; i++)
            //{
            //    Blockv0d1 temp = blockList[i];
            //    if(DistanceBetween(temp.center, nextPos) <= temp.size.Width + radius)
            //    {

            //        tempPos = temp.center;
            //        angleTorc = AngleBetween2(position, tempPos);
            //        modAngle = AngleBetween(position, tempPos);

            //        if(modAngle > 40/180*pi && modAngle < 50/180*pi)
            //        {
            //            if(DistanceBetween(temp.center, position) < temp.size.Width * 0.8f + radius)
            //            {
            //                IsLaunched = false;

            //            }
            //        }
            //        else if(DistanceBetween(temp.center, position) < temp.size.Width * 0.5f + radius )
            //        {
            //            IsLaunched = false;
            //        }
            //        SetRectangleCollisionSide(temp);
            //        BounceV3();
            //    }
            //}
            #endregion works pretty good, but leaves a lot of open space
        } // end of function CheckCollisionWithBlockList()
Exemplo n.º 2
0
        } // end of function Update()

        #region original CheckCollisionWithRectangle(RectangleF r)
        //public new void CheckCollisionWithRectangle(RectangleF r)
        //{
        //    // Probably need to set where on the rectangle the collision occured,
        //    //      (side or corner) N, E, S, or W for side and NE, SE, SW, NW for corner.
        //    #region code in Ballv5d5
        //    //speed = 1;
        //    //#region previous closest attempt at collision detection
        //    //distanceFromClosestCorner = DistanceBetween(position, closestCornerToBall);
        //    //angleToClosestCorner = AngleBetween2(position, closestCornerToBall);

        //    //#endregion previous closest attempt at collision detection
        //    //#region GIGGITY GIGGITY!!
        //    //PointF tempd = new PointF();
        //    //tempd.X = position.X + velocity.X;
        //    //tempd.Y = position.Y + velocity.Y;
        //    //if (UseHypLenAsTempDist())
        //    //{

        //    //    tempDist = DistanceBetween(tempd, closestCornerToBall);
        //    //    //tempDist = DistanceBetween(position, closestCornerToBall);
        //    //}
        //    //else
        //    //{
        //    //    if ((position.X < tempRect.X || position.X > tempRect.X + tempRect.Width)
        //    //        && position.Y > tempRect.Y && position.Y < tempRect.Y + tempRect.Height)
        //    //    {
        //    //        tempDist = (DistanceBetween(tempd, rc) - tempRect.Width / 2);
        //    //        //tempDist = (DistanceBetween(position, rc) - tempRect.Width / 2);
        //    //    }
        //    //    if (position.X > tempRect.X && position.X < tempRect.X + tempRect.Width
        //    //        && (position.Y < tempRect.Y || position.Y > tempRect.Y + tempRect.Height))
        //    //    {
        //    //        tempDist = (DistanceBetween(tempd, rc) - tempRect.Height / 2);
        //    //        //tempDist = (DistanceBetween(position, rc) - tempRect.Height / 2);
        //    //    }
        //    //}
        //    //if (tempDist < radius)
        //    //    IsLaunched = false;
        //    //#endregion GIGGITY GIGGITY!!
        //    #endregion code in Ballv5d5
        //    base.CheckCollisionWithRectangle(r);

        //    if (collisionDetected)
        //    {
        //        IsLaunched = false;

        //        //BounceV2();
        //        BounceV3();

        //        collisionDetected = false;
        //        //IsLaunched = true;
        //    }

        //} // end of function CheckCollisionWithRectangle(RectangleF r)
        #endregion original CheckCollisionWithRectangle(RectangleF r)
        public new void CheckCollisionWithRectangle(Blockv0d1 b)
        {
            base.CheckCollisionWithRectangle(b);

            if (collisionDetected)
            {
                IsLaunched = false;
                //BounceV2();
                //BounceV3();
                collisionDetected = false;
            }
        } // end of function CheckCollisionWithRectangle(RectangleF r)
        } // end of function LocalLoadAndReset()

        public void LoadBlockList(List <Blockv0d1> bList)
        {
            blockList.Clear();
            collisionPointList.Clear();
            for (int i = 0; i < bList.Count; i++)
            {
                blockList.Add(bList[i]);
            }
            for (int i = 0; i < blockList.Count; i++)
            {
                Blockv0d1 tempblock = blockList[i];
                for (int j = 0; j < tempblock.ccMarkerList.Count; j++)
                {
                    collisionPointList.Add(tempblock.ccMarkerList[j].position);
                }
            }
        }
Exemplo n.º 4
0
        private void SetRectangleCollisionSide(Blockv0d1 b)
        {
            float angleToRectCenter = AngleBetween2(b.center, position);

            if (angleToRectCenter <= pi / 4 || angleToRectCenter >= (2 * pi) - pi / 4)
            {
                rectCollisionSide = CardinalDirections.East;
            }
            if (angleToRectCenter > pi / 4 && angleToRectCenter <= pi - pi / 4)
            {
                rectCollisionSide = CardinalDirections.South;
            }
            if (angleToRectCenter > pi - pi / 4 && angleToRectCenter <= pi + pi / 4)
            {
                rectCollisionSide = CardinalDirections.West;
            }
            if (angleToRectCenter > pi + pi / 4 && angleToRectCenter < 2 * pi - pi / 4)
            {
                rectCollisionSide = CardinalDirections.North;
            }
        } // end of function SetRectangleCollisionSide(Blockv0d1 b)
 private void SetRectangleCollisionSide(Blockv0d1 b, PointF cp)
 {
     rectCenter = b.center;
     //cp = ccMarkerList[ccIndex].position;      // moved to check collision function 07/18/2017
     angleToRectCenter = AngleBetween2(rectCenter, cp);
     #region attempt1
     if (angleToRectCenter <= pi / 4 || angleToRectCenter >= (2 * pi) - pi / 4)
     {
         rectCollisionSide = CardinalDirections.East;
     }
     if (angleToRectCenter > pi / 4 && angleToRectCenter <= pi - pi / 4)
     {
         rectCollisionSide = CardinalDirections.South;
     }
     if (angleToRectCenter > pi - pi / 4 && angleToRectCenter <= pi + pi / 4)
     {
         rectCollisionSide = CardinalDirections.West;
     }
     if (angleToRectCenter > pi + pi / 4 && angleToRectCenter < 2 * pi - pi / 4)
     {
         rectCollisionSide = CardinalDirections.North;
     }
     #endregion
 } // end of function SetRectangleCollisionSide(Blockv0d1 b, PointF cp)
        } // end of function LocalLoadAndReset()

        #region Original build 1
        //public override void CheckCollisionWithRectangle(RectangleF r)
        //{
        //    base.CheckCollisionWithRectangle(r);
        //    #region previous closest attempt at collision detection
        //    distanceFromClosestCorner = DistanceBetween(position, closestCornerToBall);
        //    angleToClosestCorner = AngleBetween2(position, closestCornerToBall);

        //    #endregion previous closest attempt at collision detection
        //    #region GIGGITY GIGGITY!!
        //    PointF tempd = new PointF();
        //    tempd.X = position.X + velocity.X;
        //    tempd.Y = position.Y + velocity.Y;
        //    if (UseHypLenAsTempDist())
        //    {
        //        tempDist = DistanceBetween(tempd, closestCornerToBall);
        //        //tempDist = DistanceBetween(position, closestCornerToBall);
        //    }
        //    else
        //    {
        //        if ((position.X < tempRect.X || position.X > tempRect.X + tempRect.Width)
        //            && position.Y > tempRect.Y && position.Y < tempRect.Y + tempRect.Height)
        //        {
        //            tempDist = (DistanceBetween(tempd, rc) - tempRect.Width / 2);
        //            //tempDist = (DistanceBetween(position, rc) - tempRect.Width / 2);
        //        }
        //        if (position.X > tempRect.X && position.X < tempRect.X + tempRect.Width
        //            && (position.Y < tempRect.Y || position.Y > tempRect.Y + tempRect.Height))
        //        {
        //            tempDist = (DistanceBetween(tempd, rc) - tempRect.Height / 2);
        //            //tempDist = (DistanceBetween(position, rc) - tempRect.Height / 2);
        //        }
        //    }
        //    if (tempDist < radius)
        //    {
        //        //IsLaunched = false;
        //        collisionDetected = true;
        //    }
        //    #endregion GIGGITY GIGGITY!!
        //    //base.CheckCollisionWithRectangle(r);
        //} // end of function CheckCollisionWithRectangle(RectangleF r)
        #endregion Original build 1

        #region attempting rebuild
        public new void CheckCollisionWithRectangle(Blockv0d1 b)
        {
            base.CheckCollisionWithRectangle(b);

        } // end of function CheckCollisionWithRectangle(RectangleF r)
        public void CheckCollisionWithRectangle(Blockv0d1 b)
        {
            // might add b.collisionLastFrame to prevent double bounce. 07/18/2017
            collisionDetected = false;
            block             = b;

            if (b.collisionLastFrame)
            {
                b.collisionLastFrame = false;       // In testing 07/18/2017
                //b.sb.Color = b.defaultColor;
            }
            else
            {
                for (int i = 0; i < b.ccMarkerList.Count; i++)
                {
                    if (DistanceBetween(position, b.ccMarkerList[i].position) <= radius)
                    {
                        b.collisionLastFrame = true;        // In testing 07/18/2017
                        //b.sb.Color = Color.Gold;
                        //b.collisionMarkerIndex = i;
                        for (int j = 0; j < ccMarkerList.Count; j++)
                        {
                            if (ccMarkerList[j].IsCollisionWithRect(b.rectangle))
                            {
                                ccIndex = j;
                                cp      = ccMarkerList[j].position;
                                SetRectangleCollisionSide(b, cp);
                                collisionDetected = true;
                            }
                        }
                    }
                }
                if (collisionDetected)
                {
                    BounceV3();
                    //IsLaunched = false;
                }
            }

            //for (int i = 0; i < b.ccMarkerList.Count; i++)
            //{
            //    if (DistanceBetween(position, b.ccMarkerList[i].position) <= radius
            //        /*&& b.collisionLastFrame == false*/)
            //    {
            //        for (int j = 0; j < ccMarkerList.Count; j++)
            //        {
            //            if (ccMarkerList[j].IsCollisionWithRect(b.rectangle))
            //            {
            //                ccIndex = j;
            //                cp = ccMarkerList[j].position;
            //                SetRectangleCollisionSide(b, cp);
            //                collisionDetected = true;
            //            }
            //        }
            //    }
            //}
            //if(collisionDetected)
            //{
            //    BounceV3();
            //    //IsLaunched = false;
            //}
        } // end of function CheckCollisionWithRectangle(RectangleF r)