protected override void Go() { base.Go(); if (centerX <= LeftSide()) { vx = -vx; СhangeColor(); OnHited.Invoke(this, new HitEventArgs(Side.Left)); } if (centerX >= RightSide()) { vx = -vx; СhangeColor(); OnHited.Invoke(this, new HitEventArgs(Side.Right)); } if (centerY <= TopSide()) { vy = -vy; СhangeColor(); OnHited.Invoke(this, new HitEventArgs(Side.Top)); } if (centerY >= DownSide()) { vy = -vy; СhangeColor(); OnHited.Invoke(this, new HitEventArgs(Side.Down)); } }
protected void CheckHit(int position, int sizeForm) { if (position == X) { if (position - radius <= 0) { ChangeHorizontalDirection(); OnHited?.Invoke(this, new HitEventArgs(HitType.Left)); } if (position >= sizeForm - radius) { ChangeHorizontalDirection(); OnHited?.Invoke(this, new HitEventArgs(HitType.Right)); } } if (position == Y) { if (position - radius <= 0) { ChangeVerticalDirection(); OnHited?.Invoke(this, new HitEventArgs(HitType.Top)); } if (position >= sizeForm - radius) { ChangeVerticalDirection(); OnHited?.Invoke(this, new HitEventArgs(HitType.Bottom)); } } }
private void CheckHitWall() { if (Top <= 0) { ChangeVerticalDirection(); OnHited?.Invoke(this, new HitEventArgs(HitType.Left)); } if (Top + diameter >= form.ClientSize.Height - radius) { ChangeVerticalDirection(); OnHited?.Invoke(this, new HitEventArgs(HitType.Right)); } if (Left <= 0) { ChangeHorizontalDirection(); OnHited?.Invoke(this, new HitEventArgs(HitType.Top)); } if (Left + diameter >= form.ClientSize.Width - radius) { ChangeHorizontalDirection(); OnHited?.Invoke(this, new HitEventArgs(HitType.Bottom)); } }