Managing tetrominoes collisions

Do you remember once a tetromino touches the ground we updated fieldArray array? Now the array contains the mapping of all game field cells occupied by a tetromino piece.

The idea: To check for a collision between tetrominoes we just need to add another if statement to canFit function to see if in the candidate position of the current tetromino there is a cell of the game field already occupied by a previously landed tetromino, that is the fieldArray array element is equal to 1.

The development: It's just necessary to add these three lines to canFit function:

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

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.