Code covered by the BSD License  

Highlights from
MATLABTETRIS

4.6

4.6 | 11 ratings Rate this file 92 Downloads (last 30 days) File Size: 9.36 KB File ID: #34513
image thumbnail

MATLABTETRIS

by

 

09 Jan 2012 (Updated )

Another MATLAB version of the classic game, Tetris.

| Watch this File

File Information
Description

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.

Acknowledgements

Tetris For Dummies and Tetris (Vs Ai) inspired this file.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (14)
15 Feb 2013 Jehan Ziad Ghafuri

well done , good job

13 Feb 2013 Aman Parkash Singh

good one

13 Feb 2013 Aman Parkash Singh  
12 Feb 2013 Michael

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

11 Feb 2013 Armando  
11 Feb 2013 sara ahmed  
11 Feb 2013 Hatem

excellent

11 Feb 2013 Vizimax

excellent work

07 Jan 2013 Seban

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

16 Jan 2012 David Winthrop

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

16 Jan 2012 Mingjing Zhang

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.

15 Jan 2012 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!

15 Jan 2012 Mingjing Zhang

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.

11 Jan 2012 Claudio Gelmi

Excellent work! Thanks!

Updates
12 Jan 2012

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

20 Jan 2012

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

Contact us