/// <summary> /// Acts as a drawing delegate for DrawObjectWithTransform /// After performing the necessary transformation (translate/rotate) /// DrawObjectWithTransform will invoke this method /// </summary> /// <param name="o">The object to draw</param> /// <param name="e">The PaintEventArgs to access the graphics</param> private void ShipInfoDrawer(object o, PaintEventArgs e) { Ship p = o as Ship; int shipWidth = 35; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; using (Font font1 = new Font("Times New Roman", 16, FontStyle.Bold, GraphicsUnit.Pixel)) using (Pen pen = new Pen(Brushes.White, 2f)) using (SolidBrush rectangleFiller = new SolidBrush(Color.Green)) { if (p.GetHealth() == 0) { return; } PointF pointF1 = new PointF(-(shipWidth / 2) + 4, -(shipWidth / 2) - 20); e.Graphics.DrawString(p.GetName() + " " + p.GetScore(), font1, Brushes.White, pointF1); Rectangle rec = new Rectangle(-(shipWidth / 2) + 5, -(shipWidth / 2) + 40, 27, 7); e.Graphics.DrawRectangle(pen, rec); int length = p.GetHealth() * 5; Rectangle rec2 = new Rectangle(-(shipWidth / 2) + 6, -(shipWidth / 2) + 41, length, 5); e.Graphics.FillRectangle(rectangleFiller, rec2); } }
/// <summary> /// Acts as a drawing delegate for DrawObjectWithTransform /// After performing the necessary transformation (translate/rotate) /// DrawObjectWithTransform will invoke this method /// </summary> /// <param name="o">The object to draw</param> /// <param name="e">The PaintEventArgs to access the graphics</param> private void ShipDrawer(object o, PaintEventArgs e) { Ship p = o as Ship; int shipWidth = 35; if (p.GetHealth() == 0) { e.Graphics.DrawImage(dead_ship, -(shipWidth / 2), -(shipWidth / 2), shipWidth, shipWidth); return; } if (p.isThrustOn()) { e.Graphics.DrawImage(shipImagesThrust[p.GetID() % 8], -(shipWidth / 2), -(shipWidth / 2), shipWidth, shipWidth); } else { e.Graphics.DrawImage(shipImagesCoast[p.GetID() % 8], -(shipWidth / 2), -(shipWidth / 2), shipWidth, shipWidth); } }