The Classic Tetris in MATLAB


Somewhere during the four month time of ‘blogging’ dormancy, I actually have started drafting new code, the classical Tetris, for my fun toolbox. I was thinking of Tetris because I wanted to play more with the animation. However, somewhere along the way, I forgot that I have unfinished code. Maybe because I was too busy or because I was too lazy. Fortunately, now I’m not that busy anymore and decided to finished it. At first, I wanted to make a combination game between Tetris and bejeweled and called Bejeweled Tetris. However, it turns out that I have wrong understanding of bejeweled game (Luckily, I googled it first). So, just recently, I decided to scrap the idea and continued with just the classic tetris. But, to make up for that, I also decided to make 2 alternate game modes of tetris in the code (which actually a bad idea becauase it is the alternate game modes that make the code become harder).

While a few days ago in my author note post, I posted two youtube links, please note that that  (up, no typo here, two ‘that’) was a video capture of my MATLAB Tetris before I scrapped the bejeweled idea. So, that video was wrong and please don’t watch it anymore. Here it is, the ‘right’ version of MATLAB Tetris video capture in three different game modes.

MATLAB Tetris – Game Mode 1 (Classic)

MATLAB-Tetris_01

The first mode is the classical Tetris mode, where all hanging blocks will not fall down at all. Nothing special in this code. Just the original classical Tetris game with all the plain boring white blocks:D.

MATLAB Tetris – Game Mode 2

MATLAB-Tetris_02

The second mode is what I called ColorGlued mode. In this mode, hanging blocks will fall down if they are not glued to another same-colored blocks in its neighbors (See the second video on 2:45-2:50 to see how unglued blocks fall down and fill in the gap.). So, in this mode, there is a gravity that will pull down all the blocks. However, each side-by-side same-colored blocks will fall together as one object. Because of this rule, this game mode allows combo or chain to be made (either planned or accidentally). I made this mode because I believe I’ve read somewhere about this kind of Tetris.

MATLAB Tetris – Game Mode 3

MATLAB-Tetris_03

The third mode is what I called ColorMatched mode. This mode was made because I don’t want to completely delete the code that I made for the previous ‘wrong’ version (It’s just too much work and time goes to waste). In this mode, instead of completing a line, the blocks are eliminated by putting three or more same colored box together. Here, each block acts as individual object and will always fall down to the lowest, regardless of their neighbor.

Both three modes above runs on the same code, function, and main loop. The difference between these three modes is only the function for block generation and the function for block elimination. Just like the previous game, I’m going to explain the algorithm to show you (and probably teach you how does it work). However, since the code itself is quite big and there is a lot of explanation to it, I decided I’m gonna divide the explanation into several works and write it later (because I have this new game that I have to watched:D).

So, that’s all I’m gonna write for today. The code is available for download in My MATLAB Fun Toolbox. As usual, comments and critics are welcomed. Have a nice sunday.

Regards,

0X_R

Update for this post: MATLAB Tetris – The Main algorithm

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

2 Responses to The Classic Tetris in MATLAB

  1. JH LEE says:

    really impressive!!

    but i have a question ..
    how could i make the blocks to be changed when my score over a specific points ? ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s