Moving tetrominoes down

Moving tetrominoes down obviously applies the same concept to vertical direction.

The idea: Once the DOWN arrow key has been pressed, we should call canFit function passing as arguments the candidate row value (tRow+1 as the tetromino is moving one row down) and the current column value.

The development: modify onKDown function adding the new case:

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

We also need to update canFit function to check if the tetromino would go out of the bottom boundary.

Add this new if statement to canFit function:

private function canFit(row:int,col:int):Boolean ...

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.