Skip to content

Commit b7b9d60

Browse files
Merge pull request #21 from hashbangcode/20_keys_MR_main
20: keys MR main
2 parents 3d35ad6 + a81b496 commit b7b9d60

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

four.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ function setupGrid() {
104104
for (let i = 0; i < gridMaxX; i += 1) {
105105
grid[i] = [];
106106
column = 0;
107-
const y = i * (width / gridMaxY);
107+
const yCoord = i * (width / gridMaxY);
108108
for (let j = 0; j < gridMaxY; j += 1) {
109-
const x = j * (width / gridMaxY);
109+
const xCoord = j * (width / gridMaxY);
110110
const rectWidth = width / gridMaxY;
111111
const rectHeight = height / gridMaxY;
112112
grid[i][j] = {
113113
column: j,
114114
row: i,
115-
x: x,
116-
y: y,
115+
x: xCoord,
116+
y: yCoord,
117117
width: rectWidth,
118118
height: rectHeight,
119119
};
@@ -196,17 +196,22 @@ function keyPress(evt) {
196196
if (typeof userActionKeyPress !== 'function') {
197197
return;
198198
}
199+
evt.preventDefault();
199200
switch (evt.keyCode) {
200-
case 37:
201+
case 37: // Left arrow.
202+
case 65: // "a".
201203
userActionKeyPress(KEYPRESS_LEFT);
202204
break;
203-
case 38:
205+
case 38: // Up arrow.
206+
case 87: // "w".
204207
userActionKeyPress(KEYPRESS_UP);
205208
break;
206-
case 39:
209+
case 39: // Right arrow.
210+
case 68: // "d".
207211
userActionKeyPress(KEYPRESS_RIGHT);
208212
break;
209-
case 40:
213+
case 40: // Down arrow.
214+
case 83: // "s".
210215
userActionKeyPress(KEYPRESS_DOWN);
211216
break;
212217
default:

0 commit comments

Comments
 (0)