/// <summary> /// Shows the missle on canva /// </summary> /// <param name="canva">The canva.</param> /// <param name="visibleStart">The visible map area start.</param> /// <param name="visibleFinish">The visible map area finish.</param> /// <param name="monsters">The monsters.</param> internal void Show(IGraphic canva, Point visibleStart, Point visibleFinish, IEnumerable<Monster> monsters) { if ((DestroyMe) || ((_position.X - visibleStart.X * Settings.ElemSize < 5) || (_position.Y - visibleStart.Y * Settings.ElemSize < 5) || (-_position.X + visibleFinish.X * Settings.ElemSize < 5) || (-_position.Y + visibleFinish.Y * Settings.ElemSize < 5)) || (monsters == null)) return; //Getting Monster var monster = monsters.FirstOrDefault(elem => elem.ID == _aimID); if (monster == null) { DestroyMe = true; return; } Point aimPos = new Point((int)monster.GetCanvaPos.X, (int)monster.GetCanvaPos.Y); switch (_missleType) { case eTowerType.Simple: float tang; if ((Math.Abs((_position.X - aimPos.X) - 0) > 0.01) && (Math.Abs((_position.Y - aimPos.Y) - 0) > 0.01)) tang = Math.Abs((_position.Y - aimPos.Y) / (_position.X - aimPos.X)); else tang = 1; Point secondPosition;//Position of second missle point #region Second point calculation if (_position.X > aimPos.X) { if (_position.Y > aimPos.Y) secondPosition = new Point( Convert.ToInt32(_position.X + 10 * Math.Sqrt(1 / (1 + Math.Pow(tang, 2)))), Convert.ToInt32(_position.Y + 10 * Math.Sqrt(1 / (1 + Math.Pow(1 / tang, 2))))); else secondPosition = new Point( Convert.ToInt32(_position.X + 10 * Math.Sqrt(1 / (1 + Math.Pow(tang, 2)))), Convert.ToInt32(_position.Y - 10 * Math.Sqrt(1 / (1 + Math.Pow(1 / tang, 2))))); } else { if (_position.Y > aimPos.Y) secondPosition = new Point( Convert.ToInt32(_position.X - 10 * Math.Sqrt(1 / (1 + Math.Pow(tang, 2)))), Convert.ToInt32((_position.Y + 10 * Math.Sqrt(1 / (1 + Math.Pow(1 / tang, 2)))))); else secondPosition = new Point( Convert.ToInt32(_position.X - 10 * Math.Sqrt(1 / (1 + Math.Pow(tang, 2)))), Convert.ToInt32(_position.Y - 10 * Math.Sqrt(1 / (1 + Math.Pow(1 / tang, 2))))); } #endregion canva.DrawLine(new Pen(_misslePenColor, 2), new Point((int)((_position.X - visibleStart.X * Settings.ElemSize) * Scaling) + Settings.DeltaX, (int)((_position.Y - visibleStart.Y * Settings.ElemSize) * Scaling) + Settings.DeltaY), new Point((int)((secondPosition.X - visibleStart.X * Settings.ElemSize) * Scaling) + Settings.DeltaX, (int)((secondPosition.Y - visibleStart.Y * Settings.ElemSize) * Scaling) + Settings.DeltaY)); break; case eTowerType.Splash: canva.FillEllipse(new SolidBrush(_missleBrushColor), (int)(_position.X - 5 - visibleStart.X * Settings.ElemSize) * Scaling + Settings.DeltaX, (int)(_position.Y - 5 - visibleStart.Y * Settings.ElemSize) * Scaling + Settings.DeltaY, 10 * Scaling, 10 * Scaling); canva.DrawEllipse(new Pen(_misslePenColor), (int)(_position.X - 5 - visibleStart.X * Settings.ElemSize) * Scaling + Settings.DeltaX, (int)(_position.Y - 5 - visibleStart.Y * Settings.ElemSize) * Scaling + Settings.DeltaY, 10 * Scaling, 10 * Scaling); break; } }