public CircleHitShape(CircleHitShape chs) : base(Shape.SH_CIRCLE) { drawRect = new Rectangle(); centerPos = chs.centerPos; radius = chs.radius; }
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(); } } }
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); }
public override bool IsSame(HitShape hShape) { if (hShape.sh != sh) { return(false); } if (hShape is CircleHitShape) { CircleHitShape chs = hShape as CircleHitShape; return(chs.radius == radius && chs.centerPos.X == centerPos.X && chs.centerPos.Y == centerPos.Y); } else { return(false); } }
private void pictureBox_MouseMove(object sender, MouseEventArgs e) { Point localMousePos = new Point(e.X - pictureBox.Left, e.Y - pictureBox.Top); if (localMousePos.X < 0) { localMousePos.X = 0; } if (localMousePos.Y < 0) { localMousePos.Y = 0; } labelMousePos.Text = "(" + localMousePos.X + ", " + localMousePos.Y + ")"; Point localOffset = new Point(localMousePos.X - pictureBox.Width / 2, localMousePos.Y - pictureBox.Height / 2); labelCenterOffset.Text = "Offset from Center: (" + localOffset.X + ", " + localOffset.Y + ")"; if (move) { Point mPos = new Point(e.X, e.Y); switch (state) { case State.S_DRAWCIRCLE: { if (currHitShape != null) { CircleHitShape chs = currHitShape as CircleHitShape; chs.centerPos = mPos; } break; } case State.S_DRAWRECT1: case State.S_DRAWRECT2: { if (currHitShape != null) { RectHitShape rhs = currHitShape as RectHitShape; rhs.centerPos = mPos; rhs.UpdateRect(); } break; } } pictureBox.Refresh(); } else { switch (state) { case State.S_DRAWCIRCLE: { if (currHitShape != null) { CircleHitShape chs = currHitShape as CircleHitShape; Point mPos = new Point(e.X, e.Y); Point diff = new Point(mPos.X - chs.centerPos.X, mPos.Y - chs.centerPos.Y); double length = Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y); chs.radius = Math.Max((int)length, minCircleRadius); pictureBox.Refresh(); } break; } case State.S_DRAWRECT1: { if (currHitShape != null) { RectHitShape rhs = currHitShape as RectHitShape; Point mPos = new Point(e.X, e.Y); Point diff = new Point(mPos.X - rhs.centerPos.X, mPos.Y - rhs.centerPos.Y); double length = Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y); float max = Math.Max((int)length, minCircleRadius); rhs.width = (int)max; rhs.height = minCircleRadius; //(int)max; float xDiff = diff.X; float yDiff = diff.Y; int angle = (int)(Math.Atan2(yDiff, xDiff) * 180.0 / Math.PI); rhs.angle = angle; rhs.UpdateRect(); pictureBox.Refresh(); } break; } case State.S_DRAWRECT2: { if (currHitShape != null) { RectHitShape rhs = currHitShape as RectHitShape; PointF mPos = new PointF(e.X, e.Y); PointF diff = new PointF(mPos.X - rhs.centerPos.X, mPos.Y - rhs.centerPos.Y); PointF p0 = rhs.GetPoint(0); PointF p1 = rhs.GetPoint(1); PointF p2 = rhs.GetPoint(2); PointF axisA = new PointF(p1.X - p0.X, p1.Y - p0.Y); PointF axisB = new PointF(p2.X - p1.X, p2.Y - p1.Y); Normalize(ref axisA); Normalize(ref axisB); float d = Math.Abs(Dot(diff, axisA)); float d1 = Math.Abs(Dot(diff, axisB)); d = Math.Max(d, minCircleRadius); d1 = Math.Max(d1, minCircleRadius); //d = Math.Min(d, 400); //d1 = Math.Min(d1, 400); rhs.width = (int)d; rhs.height = (int)d1; rhs.UpdateRect(); pictureBox.Refresh(); } break; } } } }
public override HitShape Copy() { CircleHitShape chs = new CircleHitShape(this); return(chs); }