Managing tetrominoes landing

The first thing to determine is: when should a tetromino be considered as landed? When it should move down but it can't. That's it. Easier than you supposed, I guess.

The idea: When it's time to move the tetromino down a row (case 40 in onKDown function), when you can't move it down (canFit function returns false), it's time to make it land and generate a new tetromino.

The development: Modify onKDown function this way:

private function onKDown(e:KeyboardEvent) {
switch (e.keyCode) {
case 37 :
...
break;
case 39 :
...
break;
case 40 :
if (canFit(tRow+1,tCol)) {
tRow++;
placeTetromino();
} else {
landTetromino();
generateTetromino();
}
break;
}
}

When you can't move down a tetromino, landTetromino function is called ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.