Skip to content

Instantly share code, notes, and snippets.

@melcor76

melcor76/main.js Secret

Created November 19, 2019 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melcor76/17e8f24693f8129730f5f9099066ff46 to your computer and use it in GitHub Desktop.
Save melcor76/17e8f24693f8129730f5f9099066ff46 to your computer and use it in GitHub Desktop.
js-tetris - hard drop
const KEY = {
SPACE: 32,
// ...
}
moves = {
[KEY.SPACE]: p => ({ ...p, y: p.y + 1 })
// ...
};
// In EventListener
if (event.keyCode === KEY.SPACE) {
// Hard drop
while (board.valid(p)) {
board.piece.move(p);
p = moves[KEY.DOWN](board.piece);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment