From 8668796a87e310e770917384aa0cb5de59aba311 Mon Sep 17 00:00:00 2001 From: flykhan Date: Tue, 14 Feb 2023 17:45:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=9B=87=E8=BA=AB=E7=BB=93=E7=82=B9=E5=AE=BD?= =?UTF-8?q?=E5=BA=A6=E6=AF=94=E4=BE=8B=E8=B0=83=E6=95=B4=E4=B8=BA=E5=B8=B8?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/assets/scripts/Snake.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/src/assets/scripts/Snake.js b/web/src/assets/scripts/Snake.js index cbd8782..b2a7a0f 100644 --- a/web/src/assets/scripts/Snake.js +++ b/web/src/assets/scripts/Snake.js @@ -181,13 +181,15 @@ export class Snake extends AcGameObject { if (Math.abs(a.x - b.x) < this.eps && Math.abs(a.y - b.y) < this.eps) continue; + // 定义蛇身结点宽度比例 + const snake_node_width = 0.7; // 如果两个目标点在竖方向重合(横坐标一致,纵坐标不重合)时的画法 if (Math.abs(a.x - b.x) < this.eps) { - ctx.fillRect((a.x - 0.35) * L, Math.min(a.y, b.y) * L, L * 0.7, Math.abs(a.y - b.y) * L); + ctx.fillRect((a.x - snake_node_width / 2) * L, Math.min(a.y, b.y) * L, L * snake_node_width, Math.abs(a.y - b.y) * L); } // 横方向的画法 else { - ctx.fillRect(Math.min(a.x, b.x) * L, (a.y - 0.35) * L, Math.abs(a.x - b.x) * L, L * 0.7); + ctx.fillRect(Math.min(a.x, b.x) * L, (a.y - snake_node_width / 2) * L, Math.abs(a.x - b.x) * L, L * snake_node_width); } } }