Check out my
new book!
HTML5 Games book
DOMTRIS - Yet another Tetris clone I don't know how many JavaScript Tetris clones are out there, but I bet it's quite a few. Nevertheless, I decided I would have a go at it since it's just one of those things that a lot of people do when they're first getting into coding games but for some reason I never got around to it then and now I feel cheated.

It's a pretty standard, no frills Tetris game. There are no extra fancy features like some of the later editions, I've tried to keep it "sort of" close to the original. Clearing a line gives a certain amount of points depending on the level starting at 30 points. Clearing multiple lines gives even more points with 4 lines scoring 520 on level 1. As the level goes up, so does the speed of the falling tetrominoes. New levels begin at 500, 1000, 2000, 5000, 10000, 25000 points, etc.

The graphics, if we can call them that, are simply colored div elements. The embossed look is done with a simple CSS outset border type. I think it looks great in Firefox, Opera and Safari, but IE's borders look a bit different. That's ok, though, as I recall the appearance of these borders are not defined in the spec, so I guess IE is free to do as it pleases. It's cosmetic and not that big of a problem anyway.

You can save your progress at any time during the game by pressing "S" after which you will be presented with a URL that you can go to in order to load the saved game. What happens is that the game creates a URL to the game with a long ass querystring containing the current game state. This URL is then shortened via Tinyurl using Simon Willison's json-tinyurl service. So you get a short text string that will fit on the back of your hand, should you need to rush home from work to continue playing Tetris!

I actually had some bigger plans for this, including some interesting democratic "massively multiplayer" twists to the gameplay, but they will have to wait for now. Until then, this is just Tetris, not that that's not cool a game by itself.

Now play DOMTRIS!

⇓ 13 comments matt

Wow we have a lot in common -- I've been meaning to do this for *months*!

I prefer down = drop but that's me ;) Nicely done!

December 13, 2008 at 2:28 PM
Jacob Seidelin

Haha, cool. I'd love to see a Tetris game from you.

Yeah, I considered using down for drop, but I also like being able to just actively move the piece down a step and that only really makes sense with the down key.

December 13, 2008 at 2:44 PM

This is pretty good. If you're still willing to work on it, consider adding a little extra time to slide a tetromino after it has fallen. I have seen this in most versions.

December 14, 2008 at 1:24 AM
Jacob Seidelin

Thanks. Maybe I'll add that as an option if I get the time to put some more work into it. I'd like to also make the key setup customizable.

December 14, 2008 at 1:51 AM

hey.very nice job.
generally,very useful information at your blog.
keep on posting ;)

ps:btw have you ever created any game on a different programming language?

December 16, 2008 at 10:17 AM
Jacob Seidelin

Hey tasoss. Thanks!

Not anything that I've still got around or that is worth talking about (horrible VB games and unfinished C++ 3D game engines, ahoy). I've mainly worked with web development, so most of my experience is in that area.

December 16, 2008 at 10:46 AM

Nice idea, especially with the game state inside the url, although I question the usefulness complared to simply saving the state on the server and giving an ID in the link, which would prevent cheating ;)

Also cool idea about constructing the blocks with html borders.

December 16, 2008 at 12:38 PM
Jacob Seidelin

Who would want to cheat at Tetris, really? =) I just wanted a solution that didn't rely on any server-side stuff.

December 16, 2008 at 12:55 PM

Well, it's pretty easy to cheat now. I can save, and then keep playing right away. If I die, I go back to the previous save. If it was server side, you could make sure you can only save once D:

December 17, 2008 at 6:22 AM
Robert Schultz

Woot! More JavaScript games :)

I totally understand your ambitions to go 'totally massively multiplayer' with AJAX games. I've been meaning to create one myself (not tetris) but haven't yet put the effort into getting comet all set up and a good server side daemon running.

Keep up the good work :)

December 17, 2008 at 6:40 AM
Jacob Seidelin

@Drakim: I'm just saying that there's nothing to gain from cheating. it's not like there's a high score list or anything. It's like cheating at solitaire. As I said, the whole point was to try and get around needing any central server.. that and creative use of Tinyurl!

@Robert: What I had planned was some sort of democratic tetris where everyone would basically be playing the same game and the "move" that got the most "votes", ie. the one most players performed, would be the one that would stick. Bonus points for picking the correct move. Don't know if that makes any sense. Hope I get around to doing it someday.

December 17, 2008 at 7:21 AM

Hmmm, an interesting idea. If we were to drop the central server, several people could host the game and you could take your save state from one website to another.

Such a concept could be interesting if you had an RPG instead of Tetris, and each website's game was diffrent (diffrent monsters). Ofcourse, then cheating WOULD become very popular. heh.

December 18, 2008 at 3:52 AM
Jacob Seidelin

Exactly, nice idea with the RPG. And as long you're only cheating yourself, I don't see it as a problem.

December 18, 2008 at 3:57 AM
Post a Comment