Javascript Game Spotlight: 3d Worm
I was browsing the Frihost forums this morning, and I stumbled on a cool Javascript game.
One of the Frihost users and his friend made a 3d Worm game. Although the directions are in Spanish (as is the source code), the game is pretty cool. It’s a good example of what you can accomplish with some Javascript/DOM trickery.
Playing the game is simple enough. You use the four arrow keys and the Q/A key to pick one of six directions to go in.
At first, it can be very difficult to gauge the “3d” position of the apple. Once you learn to use the shadows to your advantage, the game becomes pretty easy. It’s still fun, though, and a great example of how Javascript can be used to make an interface for a game.
You see a few cool things here.
For one, the script captures keyboard input to drive the action. Rather than clicking on buttons/boxes on the screen, the user can hit the appropriate keys and the game responds. This is important for making a game feel “real” and not a kind of mash-up.
A lot of the positioning is done with “position: absolute” and the “top”/”left” styles. This let’s you use the screen as a kind of canvas - drawing the images where-ever you need them. It frees you from the constraints of normal HTML positioning, where you need to float/margin/padding stuff to get it to line up where you want.
It’s possible to read source code written in another language. I just find this interesting. The source is written in Spanish - so most of the variable/function names don’t mean a lot to me. However, the code is pretty straightforward so it’s still easy enough to follow what’s going on.
Well go play some Worm. This has inspired me to go do some coding.
Tags: game, Game Design, graphics, input, javascript







Lauren said this on March 5th, 2009 at 12:36 am
Please, can you PM me and tell me few more thinks about this, I am really fan of your blog…gets solved properly asap.
Belvendarn said this on March 5th, 2009 at 12:36 am
This was such an informative, relevant answer. It was exactly what I was looking for. I’m so happy to know I’ll be getting something out of you posts.