Categories
Game Development Personal Development

Game Programming Tutorial: Tetris in C++

Javier Lopez wrote a beginner’s tutorial to write Tetris in C++. NOTE: It seems this link is broken. I’ll see if I can find a replacement. The tutorial is platform-independent, which I like. While some people have complained that the tutorial isn’t very good C++, I’ve yet to see a more comprehensive and complete Tetris tutorial. Once you’ve followed it and written your own, feel free to spend the time to write a better one.

Full disclosure: I’ve never written a Tetris clone.

WHAT?! Haven’t ALL game developers worth their salt made their own Tetris? Didn’t icculus say that it was good for the soul?

I’m not going to say that I’m proud of it, but for some reason the furthest I ever got was to write some notes down. I would think about how to represent the various pieces, but I would get hung up on not easily seeing a general way to do so. I could have hard-coded them the way the tutorial does, but I thought, “Nah, I can do it better than that!”

But then I never did it. And so I never wrote a Tetris clone at all.

For new game developers out there, you have to realize that shortcuts and brute force methods are perfectly fine sometimes. It’s more important to get something working, even if it is working badly, than it is to get it right the first time. Otherwise, you spend years tweaking a general purpose game engine.

Lopez’s tutorial will do more to help someone understand basic game logic than most game engine tutorials, and the end result will be a pretty good clone of the original Tetris. The player isn’t going to care that you didn’t use every bit of functionality that C++ (or any language) provides. You made a game, and that’s all that matters.

[tags] tetris clone, game development, tutorial [/tags]

7 replies on “Game Programming Tutorial: Tetris in C++”

Wow, now I’m blushing. Thanks for the backlink, Gianfranco.

In fact, I tried to write the tutorial in the most legible way possible, because it is mostly for beginners.

If people found mistakes on it… I dont’t want to know what would they say about my 2d engine: IndieLib. It’s source code should be plenty of wrong things 🙂

PS: my first game system was also the Atari 2600 and I like Steve Pavlina blog too 🙂

No problem, Javier! Thanks for writing a good tutorial! I’m sure it helped a lot of beginners with understanding basic game programming.

Tetris isn’t a very exciting project, but its a good exercise that can be finished in a couple of days work. Its fun to play also, and its not very hard to get the feel\game rules of tetris right, so chances are your tetris clone will be fun to play. This isn’t necessarily true when people clone a lot of other games. Its very easy to make bad versions of “simple” games like Pacman, Donkey Kong, Frogger or even Pong.

GB – I’m ashamed of you, because even *I* wrote a tetris clone.

Impossible – YOU may be able to finish a tetris clone in a couple of days, but mine took me about 8 months. Granted it was my first game, but it did take me that long.

Keith

Keith – I agree. If you’re learning your language of choice or learning how to program for the first time and\or learning new concepts and APIs it could easily take 8 months or longer to get a working tetris clone. I was speaking to GB as an experienced programmer who has worked on multiple games, not as a learner working on his first project.

LD48 is a waste of time but its still fun! I haven’t entered LD48 in a while because, although I still love rapid development, I don’t really like the time limit and the theme restrictions that LD48 gives you. I’ve found it more enjoyable to develop games randomly and quickly with no stress simply because I feel like working on something.

Comments are closed.