示例#1
0
        private void pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            Point mPos = new Point(e.X, e.Y);

            if (e.Button == MouseButtons.Left)
            {
                switch (state)
                {
                case State.S_DRAWCIRCLE:
                {
                    currHitShape = new CircleHitShape();
                    CircleHitShape chs = (CircleHitShape)currHitShape;
                    chs.centerPos.X = e.X;
                    chs.centerPos.Y = e.Y;
                    chs.radius      = minCircleRadius;
                    break;
                }

                case State.S_DRAWRECT1:
                {
                    currHitShape = new RectHitShape();
                    RectHitShape rhs = (RectHitShape)currHitShape;
                    rhs.SetRect(mPos, minCircleRadius, minCircleRadius, 0);
                    break;
                }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (currHitShape != null)
                {
                    currHitShape = null;
                    if (state == State.S_DRAWRECT2)
                    {
                        state = State.S_DRAWRECT1;
                    }
                }
                else
                {
                    List <HitShape> hList = hitboxLists[currFrame - minFrame];
                    foreach (HitShape ht in hList.Reverse <HitShape>())
                    {
                        if (ht.HasPoint(mPos))
                        {
                            hList.Remove(ht);
                        }
                        //if contains mouse position, then remove the hitbox
                    }
                    pictureBox.Refresh();
                }
            }
        }
示例#2
0
        static public HitShape Load(StreamReader sr, Point gCenter)
        {
            int shapeType = Convert.ToInt32(sr.ReadLine());

            Shape sha = (Shape)shapeType;

            switch (sha)
            {
            case Shape.SH_CIRCLE:
            {
                int centerX = Convert.ToInt32(sr.ReadLine());
                int centerY = Convert.ToInt32(sr.ReadLine());
                int radius  = Convert.ToInt32(sr.ReadLine());

                CircleHitShape chs = new CircleHitShape();
                chs.radius      = radius;
                chs.centerPos.X = centerX + gCenter.X;
                chs.centerPos.Y = centerY + gCenter.Y;
                return(chs);

                break;
            }

            case Shape.SH_RECT:
            {
                int centerX = Convert.ToInt32(sr.ReadLine());
                int centerY = Convert.ToInt32(sr.ReadLine());

                centerX = centerX + gCenter.X;
                centerY = centerY + gCenter.Y;

                int width  = Convert.ToInt32(sr.ReadLine());
                int height = Convert.ToInt32(sr.ReadLine());
                int angle  = Convert.ToInt32(sr.ReadLine());

                RectHitShape rhs = new RectHitShape();
                rhs.SetRect(new Point(centerX, centerY), width, height, angle);

                return(rhs);

                break;
            }
            }

            return(null);
        }