File Exchange

image thumbnail

MATLABTETRIS

version 1.2 (9.36 KB) by

Another MATLAB version of the classic game, Tetris.

4.46154
16 Ratings

126 Downloads

Updated

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 (20)

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

priya (view profile)

well done , good job

good one

Michael

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

Armando

sara ahmed

Hatem

Hatem (view profile)

excellent

Vizimax

excellent work

Seban

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

Loginatorist

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!

Updates

1.2

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

1.1

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

MATLAB Release
MATLAB 7.5 (R2007b)

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

» Watch video