File Exchange

image thumbnail


version 1.2 (9.36 KB) by

Another MATLAB version of the classic game, Tetris.

16 Ratings



View License

Pushing the following keys has the listed effect:

Key Effect
n.....Starts a new game in the middle of any game.
p.....Pauses/Unpauses game play.
s.....Starts the new game (alternative to pushing the start button).

Other tips:

To move the piece, use the arrow keys.
The up arrows rotates a piece clockwise, shift+up, counter clockwise.
Clicking on the preview window hides/unhides the preview (next piece).
Click on the level (1) before starting a game to choose start level. If the first level is too slow, try starting out at a higher level, up to 9. The desired starting level may also be passed in as an argument when first calling the game. For example,


starts the game at level 7.

Certain alterations should be easy for experienced MATLAB users, such as altering the number of lines required to advance to the next level and the acceleration rate level-to-level, as the code is well-commented. If it is desired to change these things but too difficult, feel free to contact me for assistance.
See the help in the file for more important information. If this game is found to have bugs, please contact me via email with a detailed message.

Comments and Ratings (21)

Ayan Khan

When i try to run this code i get erros plz someone tell me the initials steps i am bignner


Hi Matt!

Just so you know, I've added Kinect and Wii Balance Board controls to your code. Gives an interesting new gameplay!

If you are interested to try it, it's available to download on the user community (search for Tektris)!


priya (view profile)

well done , good job

good one


Is there a way to change the shape of the pieces?


sara ahmed


Hatem (view profile)



excellent work


Seban (view profile)

Only 4 stars, because there's still no 'I need a long block'-button implemented :D

Looks good, runs good. No problems. I think it is really amazing! Nice little EasterEgg in there too (wink-wink).

Mingjing Zhang

Mingjing Zhang (view profile)

Yeah, my laptop is kinda old. Upon a closer examination, however, I noticed that the game is only 'sluggish', i.e. the movement of the block is not smooth, only when I hold the 'down' key.

I think it might not be that hard to change them to images, since the blocks have a very simple and symmetrical spatial structure. I believe they can be generated procedurally rather than hard-coded. For example, the following code will generate a simple block (index image):
a = ones(16,16);
[x y] = meshgrid(1:16);

Anyway I think this game is already almost perfect. I just want to share with you how I would have written it.


Loginatorist (view profile)

Thanks for your comment Mingjing! I am surprised that the game is sluggish on your laptop, as I tested it on 3 laptops out of concern over its graphics-intensive nature. I guess my sample was too small!

One of the goals in making the game was to be able to have everything in one file, which is why I didn't use an image (or any of the other approaches I could have). Now I wonder if I could created the image from repmatting a hard-coded matrix inside the file? I will look into this in the coming weeks when I get time, and see if it speeds things up at all. Thanks for the idea!

Mingjing Zhang

Mingjing Zhang (view profile)

Very good one! Probably the best-looking Tetris on this site(Although it runs a little sluggish on my laptop.)

I believe its performance could be improved by using 1~2 image objects instead of 19x9 patch objects: Regard the whole playfield (including the 'frame' and all the 'fixed' blocked at the bottom) as an image object and the currently falling block as another. Or you can treat everything as one image object, since the background is just one simple color.

Claudio Gelmi

Claudio Gelmi (view profile)

Excellent work! Thanks!



Bug fix. An error was produced by clicking on a border block because the handlevisibility was 'off' instead of 'callback'.


Made it easier for programmers to change level steps and acceleration. Other minor housekeeping alterations.

MATLAB Release
MATLAB 7.5 (R2007b)

MATLAB Online Live Editor Challenge

Win cash prizes and have your live script featured on our website

Learn more

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video