import Toybox.Lang; import Toybox.Graphics; // Draws a top-down padel court centered at (cx, cy) and a yellow serve ball // in the given quadrant. Half-width HW and half-height HH keep it inside the // central band of the round screen. class CourtRenderer { private const HW = 92; // half court width (px) private const HH = 95; // half court height (px) private const BALL_R = 7; // bgColor fills the court surface (blue for now; a future settings screen // will drive it via RulesConfig). public function draw(dc as Graphics.Dc, cx as Number, cy as Number, quadrant as Number, showBall as Boolean, bgColor as Number) as Void { var left = cx - HW; var top = cy - HH; // Service line sits 3m from the back wall (7m from the net) on a 10m // half, i.e. 0.7 of the way from the net to the back boundary. var sl = (7 * HH) / 10; dc.setColor(bgColor, Graphics.COLOR_TRANSPARENT); dc.fillRectangle(left, top, 2 * HW, 2 * HH); // court surface dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT); dc.setPenWidth(2); dc.drawRectangle(left, top, 2 * HW, 2 * HH); // outer boundary dc.drawLine(left, cy - sl, left + 2 * HW, cy - sl); // upper service line dc.drawLine(left, cy + sl, left + 2 * HW, cy + sl); // lower service line dc.drawLine(cx, cy - sl, cx, cy + sl); // center line (between service lines only) dc.setPenWidth(4); dc.drawLine(left, cy, left + 2 * HW, cy); // net (boldest) if (showBall) { var pos = _ballPos(quadrant, cx, cy); dc.setColor(Graphics.COLOR_YELLOW, Graphics.COLOR_TRANSPARENT); dc.fillCircle(pos[0], pos[1], BALL_R); } } private function _ballPos(quadrant as Number, cx as Number, cy as Number) as Array { var dx = HW / 2; var dy = (17 * HH) / 20; // centered in the back zone, farthest from the net if (quadrant == QUAD_BOTTOM_RIGHT) { return [cx + dx, cy + dy]; } if (quadrant == QUAD_BOTTOM_LEFT) { return [cx - dx, cy + dy]; } if (quadrant == QUAD_UPPER_LEFT) { return [cx - dx, cy - dy]; } return [cx + dx, cy - dy]; // QUAD_UPPER_RIGHT } }