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); } } }