Exemplo n.º 1
0
        public int CollisionState(Sprite s)
        {
            if (IsCircleShape())
            {
                if (!s.IsCircleShape())
                {
                    PointF centerP = new PointF((Bounds.Left + Bounds.Right) / 2, (Bounds.Top + Bounds.Bottom) / 2);
                    if (GameControl.IsIntersected(centerP, Width / 2, s.Bounds))
                    {
                        float leftdist   = s.Bounds.Left - centerP.X;
                        float rightdist  = centerP.X - s.Bounds.Right;
                        float topdist    = s.Bounds.Top - centerP.Y;
                        float bottomdist = centerP.Y - s.Bounds.Bottom;

                        int   ret     = 4;
                        float highest = leftdist;

                        if (rightdist > highest)
                        {
                            highest = rightdist;
                            ret     = 2;
                        }
                        if (topdist > highest)
                        {
                            highest = topdist;
                            ret     = 1;
                        }
                        if (bottomdist > highest)
                        {
                            highest = bottomdist;
                            ret     = 3;
                        }

                        return(ret);
                    }
                }
            }
            return(0);
        }