-2

I'm trying to make Tetris using javascript.

https://github.com/meth-meth-method/tetris -- I found this on Youtube and started to add some other functions.

I want to add Hard drop key in this Tetris game.

function playerDrop() {
    player.pos.y++;
    if (collide(arena, player)) {
        player.pos.y--;
        merge(arena, player);
        playerReset();
        arenaSweep();
        updateScore();
    }
    dropCounter = 0;
}

This is just normal drop function. How to make a hard drop function out of it?

halfer
  • 19,824
  • 17
  • 99
  • 186
loone96
  • 723
  • 2
  • 13
  • 21

1 Answers1

1

I presume by 'Hard Drop' you mean to drop to the bottom on one key press?

If so, perhaps the follwing.

function playerDropHard() {
    while (!collide(arena, player)) {
        player.pos.y++;
    }
    player.pos.y--;
    merge(arena, player);
    playerReset();
    arenaSweep();
    updateScore();
    dropCounter = 0;
}
amcquaid
  • 539
  • 2
  • 9