GrandTabernacleAutoVI/js/input.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-11-15 09:09:13 +01:00
class Input {
constructor(id) {
this.canvas = document.getElementById(id);
this.mouseX = 0
this.mouseY = 0
// Event listener pour la position de la souris
this.canvas.addEventListener("mousemove", this.handleMouseMove.bind(this))
this.canvas.addEventListener("click", function(event) {
console.log("Clic de la souris");
});
window.addEventListener("keydown", function(event) {
switch(event.key) {
case "ArrowUp":
console.log("Flèche du haut");
break;
case "ArrowDown":
console.log("Flèche du bas");
break;
case "ArrowLeft":
console.log("Flèche de gauche pressée");
break;
case "ArrowRight":
console.log("Flèche de droite pressée");
break;
}
});
}
handleMouseMove(event) {
let mX = event.clientX - this.canvas.getBoundingClientRect().left;
let mY = event.clientY - this.canvas.getBoundingClientRect().top;
this.mouseX = mX
this.mouseY = mY
}
calculateAngle(playerX, playerY) {
return Math.atan2(this.mouseY - playerY, this.mouseX - playerX) //Math.atan2(
}
}