Moving tetrominoes horizontally

Players should be able to move tetrominoes horizontally with arrow keys (and any other keys you want to enable, but in this chapter we'll only cover arrow keys movement).

The idea: Pressing LEFT arrow key will make the current tetromino move to the left by one tile (if allowed) and pressing RIGHT arrow key will make the current tetromino move to the right by one tile (if allowed).

The development: The first thing which comes to mind is some tetrominoes in some rotations can have the leftmost column empty, just as it happened with the first row. For this reason, it's better to declare tCol variable as an integer since it can assume negative values when you next move the tetromino to the left edge of the game field. ...

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.