Building Tetris

March 18th, 2009  | By: Daichi  | Categories: Programming, Projects  | Tags: , ,

In my last post, I talked about my Tetris Clone I wrote. Since my last post, I felt like I should talk about making a Tetris clone in general.

I noticed while porting my code to Flash, there is now a ton more resources that help break down the game. In this blog post by Luke at Terminally-incoherent, Luke explains what details make up the Tetris game in a mini design document. While his document is nice, it made me aware something even better, the really cool wiki. Something that wasn’t around when I wrote my original code for the game. This wiki taught me some terminology I didn’t know about before, such as “Wall Kick”, which is what allows you to move a piece while it is against a wall. I coded this feature because I noticed it in other Tetris games I played, but I never knew a name for it. The site also gives names to many of the popular rotation systems and talks a little about game strategy.

I didn’t change any of the core code in my port. So it is fairly identical to my original C++ code in functionality. But if this wiki existed when I put my clone together, I could of cut my original programing time in half. I originally programmed the game code in about a week and I remember spending about two days just figuring out the code needed to rotate a block. However, It is not a bad idea to figure out the concepts yourself. It certainly was good practice for me.

I don’t know if anyone will find it useful, but I decided to share the source code for my ActionScript 3 Flash port of the game. I figure that my Flash port more practical to share, since my C++ code uses DirectX 7, a graphics engine which is a little out of date. (The DirectX 7 port is actually more complex, due to things like window initialization, graphics initialization and windows event handlers. Which might just add to confusion.)

Source: Here

The only thing I’ve done since my last post was add some comments to the source.

A little about the code.

I thought it was kind of silly but while trying to figure out how to draw to the screen in Flash, I just decided it would just be easier to use a single Flash sprite for each possible position on the map and turn the sprites on and off as needed. Well hey, it works just fine like this. I don’t have to worry about copying images to certain locations on screen this way.

I do love how simple my main Flash file is. It just has one layer with one line of code to run my main class.

new Game(this);

Which means everything aside from the original stage is generated by code. An idea I got from the code on the Flash video player I started using on this site recently. It’s just nice and simple this way.

I still plan to go back and add a pause feature to this game, I just don’t have time right now.

Please let me know if you find any of this code useful.

  1. July 31st, 2009 at 06:07
    Reply | Quote | #1

    I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.


1 trackbacks/pingbacks