Improve key input

This commit is contained in:
Marcel
2019-04-08 21:59:43 +02:00
parent 9dc90621ab
commit e4d127936f

23
game.js
View File

@@ -45,7 +45,7 @@ class Game {
this.restartButton = document.getElementById('restart-btn');
this.fieldSize = {x: 16, y: 12};
this.bombCount = this.fieldSize.x * this.fieldSize.y * .25;
this.bombCount = this.fieldSize.x * this.fieldSize.y * .2;
this.field = [];
this.gameOver = false;
this.scaleFactor = .5;
@@ -323,7 +323,7 @@ class Game {
this.rightClickEventHandler(e);
});
window.addEventListener("keyup", (e) => {
window.addEventListener("keypress", (e) => {
e.preventDefault();
const changeRate = .05;
@@ -332,20 +332,23 @@ class Game {
let newWindowX = this.windowX;
let newWindowY = this.windowY;
if (e.code === "BracketRight") {
if (e.code === "BracketRight" || e.key === "e") {
newZoomFactor -= changeRate;
} else if (e.code === "Slash") {
}
if (e.code === "Slash" || e.key === "q") {
newZoomFactor += changeRate;
} else if (e.code === "ArrowLeft") {
}
if (e.code === "ArrowLeft" || e.key === "a") {
newWindowX -= changeRate;
} else if (e.code === "ArrowRight") {
}
if (e.code === "ArrowRight" || e.key === "d") {
newWindowX += changeRate;
} else if (e.code === "ArrowUp") {
}
if (e.code === "ArrowUp" || e.key === "w") {
newWindowY -= changeRate;
} else if (e.code === "ArrowDown") {
}
if (e.code === "ArrowDown" || e.key === "s") {
newWindowY += changeRate;
} else {
return;
}
newZoomFactor = Math.min(newZoomFactor, 1);