File Exchange

image thumbnail

MATLABTETRIS

version 1.2.0.0 (9.36 KB) by Matt Fig
Another MATLAB version of the classic game, Tetris.

86 Downloads

Updated 20 Jan 2012

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,

matlabetetris(7)

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.
Thanks.

Comments and Ratings (24)

We're trying to add the speech recognition to the Tetris path, and want to control the blocks with commands like "up", "down", "Turn left" and "Turn right". Is there someone that could help us with showing us the way implementing this into the code of the game. Kind regards.

Hello!!! there I currently taking this subject which is called COMPUTER VISION AND IMAGE PROCESSING and this subject has linking to implement a game. So i required to implement a tetris game and i also new to matlab. Is there anyone there can teach me how to implement tetris game step by step because i want to what happen on each of function is being created instead of just copy and paste people code to the matlab. I hope to get reply as soon as possible. Thank You

Hi, I'm hoping to use this code to run in an experiment, but I need to change the board array to a 15x20 (as opposed to your 10x20). Can you provide tips to do this?

Ayan Khan

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

Pariterre

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

well done , good job

good one

Michael

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

Armando

sara ahmed

Hatem

excellent

Vizimax

excellent work

Seban

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).

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);
a((x<=3|y<=3)&(x<=16-y))=0;
a((x>=14|y>=14)&(x>16-y))=2;
imagesc(a)
--

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

Matt Fig

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!

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.

Excellent work! Thanks!

Updates

1.2.0.0

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

1.1.0.0

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

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux