« back

JavaScript Tetris

Tetris

Why?

I was finishing up some tedious work around midnight a few days ago and decided I needed to code something fun. I have a few projects I’m already working on so I figured I’d do something small and quick. Lately I’ve been getting interested in game programming so I wanted to do something along those lines. “But what sort of game can I make in a few hours?” I thought to myself. Then it hit me. I was going to make Tetris.

The Process

I’d never made anything like this before so I decided to implement in JavaScript since I’ve been doing a lot of JavaScript coding lately. I grabbed a Coke from the fridge and got to work. It took a couple of hours to throw together the internals and another hour or so to style it (CSS is not my cup of tee). I used the sweet jQuery library for all DOM manipulation and a few images I made so the blocks would look nice. It turned out pretty well and after one long night I had a nice little tetris game!

Compatibility

It works in Safari 3, Firefox 2, IE 6 & 7, and Opera 9 (those are all the browsers I have installed) with the only caveat being that Opera doesn’t continuously fire the onkeydown event while a button is pressed, so dropping blocks quickly in Opera requires multiple taps on the down arrow.

Source Code

The code, styles, images, and markup are available here in case anyone wants to fix any bugs they find or use it as a studying tool (the code is commented, but it was late so the comments are not as detailed as they could be).

Well enough talk! Check it out!

[3] Comments

 

3 Comments

I really like tetris, I waiste all of my time at work playing it.


Awesome! … just what I needed to pass some time!

  • At: 5:40 pm
  • On: 24 // 02 // 2009
  • By: Adam

It’s been a long time since I’ve played Tetris. Thanks for getting me off of twitter for an hour.

  • At: 9:52 pm
  • On: 5 // 06 // 2009
  • By: Jay

 Leave a Comment 


Archived Posts

  • jScroll HorizontalPane

    14 // 07 // 2008

    jScrollHorizontalPane is a plugin based off of Kevin Luck’s jScrollPane which override’s the browsers…

  • JavaScript Tetris

    8 // 08 // 2008

    Why?

    I was finishing up some tedious work around midnight a few days ago and decided I needed to code something fun. I have…

  • Get page tag id’s based on a category in Wordpress

    27 // 10 // 2009

    For the new threeformed site I am using Wordpress as a light CMS, so I wanted to treat some ’special’ posts d…

  • jQuery ClickScroller Plugin

    23 // 02 // 2010

    This is a simple jQuery plugin used to create a horizontal or vertical clicking scroll menu. It’s lightweight, s…


Linkage