蛇身结点宽度比例调整为常量
This commit is contained in:
parent
369f474fab
commit
8668796a87
|
@ -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)
|
if (Math.abs(a.x - b.x) < this.eps && Math.abs(a.y - b.y) < this.eps)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// 定义蛇身结点宽度比例
|
||||||
|
const snake_node_width = 0.7;
|
||||||
// 如果两个目标点在竖方向重合(横坐标一致,纵坐标不重合)时的画法
|
// 如果两个目标点在竖方向重合(横坐标一致,纵坐标不重合)时的画法
|
||||||
if (Math.abs(a.x - b.x) < this.eps) {
|
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 {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue