private void drawRobotBody(Robot robot, Pen pen, Graphics g) { PointF[] spike = DrawerUtils.Rotate(AngleUtils.ToRads(robot.ANGLE), PointF.Empty, DefaultDrawer.spike); PointF[] bottom = DrawerUtils.Rotate(AngleUtils.ToRads(robot.ANGLE), PointF.Empty, DefaultDrawer.bottom); PointF robotPosition = robot.GetPosition(); Pen teamPen = DefaultDrawer.GetTeamPen(robot.TEAM_ID); lock (g) { lock (teamPen) { float oldTeamPenWidth = teamPen.Width; teamPen.Width = 5; g.DrawLines(teamPen, DrawerUtils.Translate(robotPosition, spike)); teamPen.Width = oldTeamPenWidth; } lock (pen) { pen.Width = 5; g.DrawLines(pen, DrawerUtils.Translate(robotPosition, bottom)); } lock (Brushes.Red) { g.FillEllipse(Brushes.Red, robotPosition.X - 1, robotPosition.Y - 1, 2, 2); } } }
/// <summary> /// Draw robot on graphics context. When robot HP is 0, then it will not be drawn. /// </summary> /// <param name="robot">robot with should be drawn</param> /// <param name="g">graphics context</param> public void DrawRobot(Robot robot, Graphics g) { if (robot.HIT_POINTS <= 0) { return; } Pen pen = GetRobotPen(robot); drawRobotBody(robot, pen, g); Font drawFont = new Font("Arial", 10); string drawString = $"{robot.NAME}:{robot.ID} ({robot.HIT_POINTS})"; lock (g) { lock (pen) { g.DrawString(drawString, drawFont, pen.Brush, DrawerUtils.Translate(robot.GetPosition(), name)); } } }
/// <inheritdoc /> public void DrawScan(Scan scan, Graphics g, int turn) { int index = turn; Pen pen = scannerPen[index]; double startAngle = scan.ANGLE - scan.PRECISION + 360; double stopAngle = scan.ANGLE + scan.PRECISION + 360; if (turn == 0) { PointF scanPosition = scan.GetPosition(); PointF endScan1 = DrawerUtils.Translate(scanPosition, DrawerUtils.Rotate(AngleUtils.ToRads(startAngle), PointF.Empty, new PointF((float)scan.DISTANCE, 0F))); PointF endScan2 = DrawerUtils.Translate(scanPosition, DrawerUtils.Rotate(AngleUtils.ToRads(stopAngle), PointF.Empty, new PointF((float)scan.DISTANCE, 0F))); lock (g) { lock (pen) { pen.Width = 2; g.DrawLine(pen, scanPosition, endScan1); g.DrawLine(pen, scanPosition, endScan2); } } } RectangleF circle = new RectangleF( (float)(scan.X - scan.DISTANCE), (float)(scan.Y - scan.DISTANCE), (float)scan.DISTANCE * 2, (float)scan.DISTANCE * 2 ); if (scan.PRECISION > 0 && scan.DISTANCE > 0) { lock (g) { lock (pen) { g.DrawArc(pen, circle, (float)startAngle, (float)scan.PRECISION * 2); } } } }