Rotating tetrominoes

The concept behind a tetromino rotation is not that different than the one behind its movement.

The idea: We have to see if the tetromino in the candidate rotation fits in the game field, and eventually apply the rotation.

The development: The first thing to do is to change canFit function to let it accept a third argument, the candidate rotation. Change it this way:

private function canFit(row:int,col:int,side:uint):Boolean {
var ct:uint=currentTetromino;
for (var i:int=0; i<tetrominoes[ct][side].length; i++) {
for (var j:int=0; j<tetrominoes[ct][side][i].length; j++) {
if (tetrominoes[ct][side][i][j]==1) {
return true;

As you can see there's nothing difficult in it: I just added a third argument called side ...

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.