|
|
@ -78,7 +78,9 @@ export default class SnakeClass extends SnakeControl { |
|
|
this.start(); |
|
|
this.start(); |
|
|
this.addControl(); |
|
|
this.addControl(); |
|
|
} |
|
|
} |
|
|
dispose() {} |
|
|
|
|
|
|
|
|
dispose() { |
|
|
|
|
|
this.destroy(); |
|
|
|
|
|
} |
|
|
addControl() { |
|
|
addControl() { |
|
|
let controller = this.buttons; |
|
|
let controller = this.buttons; |
|
|
let curDirection; |
|
|
let curDirection; |
|
|
@ -93,25 +95,10 @@ export default class SnakeClass extends SnakeControl { |
|
|
deg270 = Math.PI + deg90, |
|
|
deg270 = Math.PI + deg90, |
|
|
deg315 = Math.PI * 2 - deg45; |
|
|
deg315 = Math.PI * 2 - deg45; |
|
|
|
|
|
|
|
|
controller.addEventListener( |
|
|
|
|
|
"touchstart", |
|
|
|
|
|
({ targetTouches: [{ clientX, clientY }] }) => { |
|
|
|
|
|
checkDirection(clientX - x, clientY - y); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
controller.addEventListener("click", ({ clientX, clientY }) => |
|
|
|
|
|
checkDirection(clientX - x, clientY - y) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
controller.addEventListener( |
|
|
|
|
|
"touchmove", |
|
|
|
|
|
({ targetTouches: [{ clientX, clientY }] }) => { |
|
|
|
|
|
checkDirection(clientX - x, clientY - y); |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
controller.addEventListener("touchend", () => { |
|
|
|
|
|
curDirection = undefined; |
|
|
|
|
|
controller.className = "buttons snake-direction"; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
let checkDirection = (x, y) => { |
|
|
let checkDirection = (x, y) => { |
|
|
let radian = Math.asin(y / Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))); |
|
|
let radian = Math.asin(y / Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))); |
|
|
// 1~2象限
|
|
|
// 1~2象限
|
|
|
|