MCPcopy
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / check

Function check

assets/js/maze.js:394–443  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

392 }
393
394 function check(e) {
395 var cell = map[cellCoords.x][cellCoords.y];
396 moves++;
397 switch (e.keyCode) {
398 case 65:
399 case 37: // west
400 if (cell.w == true) {
401 removeSprite(cellCoords);
402 cellCoords = {
403 x: cellCoords.x - 1,
404 y: cellCoords.y
405 };
406 drawSprite(cellCoords);
407 }
408 break;
409 case 87:
410 case 38: // north
411 if (cell.n == true) {
412 removeSprite(cellCoords);
413 cellCoords = {
414 x: cellCoords.x,
415 y: cellCoords.y - 1
416 };
417 drawSprite(cellCoords);
418 }
419 break;
420 case 68:
421 case 39: // east
422 if (cell.e == true) {
423 removeSprite(cellCoords);
424 cellCoords = {
425 x: cellCoords.x + 1,
426 y: cellCoords.y
427 };
428 drawSprite(cellCoords);
429 }
430 break;
431 case 83:
432 case 40: // south
433 if (cell.s == true) {
434 removeSprite(cellCoords);
435 cellCoords = {
436 x: cellCoords.x,
437 y: cellCoords.y + 1
438 };
439 drawSprite(cellCoords);
440 }
441 break;
442 }
443 }
444
445 this.bindKeyDown = function () {
446 window.addEventListener("keydown", check, false);

Callers 1

PlayerFunction · 0.70

Calls 1

removeSpriteFunction · 0.85

Tested by

no test coverage detected