View Full Version : Javascript Games, Baby!

02-05-2010, 07:01 AM
Not content with using Javascript for practical purposes, I decided to "engineer" and "physics engine" for a "game". Get ready for seconds of fun. Paste this bad boy into a new HTML file and hold on to your hats!

<!DOCTYPE HTML><html><head><style>#guy{position: absolute;width: 20px;height: 20px;background: #F00;}#playingArea{position: absolute;border: 1px solid black;border-bottom: 5px solid brown;width: 400px;height: 400px;margin: 50px;}</style><script type="text/javascript">var ground = 380;var guyX = 0;var guyY = 0;var guy;var timer = 0;var jumping = false;var jumper = 10;function render(){moveGuy();}function keyPress(e){if(!e)e = window.event;if(e.keyCode == 37 && guyX>0){guyX -= 4;guy.style.left = guyX+"px";}if(e.keyCode == 39 && guyX<380){guyX += 4;guy.style.left = guyX+"px";}if(e.keyCode == 38 && guyY>=ground){jumping = true;}if(jumping == true){guyY -= jumper;jumper--;guy.style.top = guyY+"px";if(guyY >= ground){jumper = 10;guyY = ground;jumping = false;}}}function moveGuy(){if(guyY < ground){guyY += 4;guy.style.top = guyY+"px";}}function start(){render();timer = setTimeout("start()",30);}function init(){guy = document.getElementById("guy");window.onkeypress = keyPress;start();}</script></head><body onload="init()"><div id="playingArea"><div id="guy"></div></div></body></html>

Kidding aside, anyone here ever actually make any "games" in Javascript? Or know of any cool ones?

Old Pedant
02-05-2010, 08:08 AM
Ummm...you really *ARE* kidding, aren't you!?

know of any cools ones?


02-05-2010, 03:30 PM
Ummm...you really *ARE* kidding, aren't you!?


02-05-2010, 04:10 PM
Here is a couple homebrew games.


Space Invaders

Star Wars Puzzle

Old Pedant
02-05-2010, 08:14 PM
I actually did write a game as one of my first forays into JavaScript, back in 1998 (might have been early 1999, but don't think so).

It was a maze game. Generated a maze, showed it to you, and then hid it from you. And then you had to go from entrance to exit "blind" as a timer ticked down.

It ran in MSIE 4 and NS 3. It still runs on MSIE 7, today, but it's pretty clumsy. I keep thinking that maybe I'll update it to today's browsers, but it's never really worth the time.

Anyway, it's "claim to fame" is that I entered it into a contest for "5K HTML Pages". The idea was that you had to create a complete "application" in only 5K bytes. That included HTML, JavaScript, any image files you used, etc. You were allowed to use 5120 bytes (that is, 5 * 1K, as opposed to 5 * 1000), but that was the max. I didn't win, but at least I made it into the "finals". It was pretty amazing what people managed to do in only 5K bytes. I present it here only as a curiosity piece:


Again, it does *NOT* work in FF or other similar browsers and I dunno about MSIE 8. Why didn't I use the cursor keys, instead of the "arrows" on the numeric keypad? Because that would have taken several more bytes of code.

02-05-2010, 09:04 PM
I have created a lot of JavaScript games several years ago when I was just starting to learn JavaScript. I created Memory game, Master Mind game, Othello, etc.

Two of them are posted on the Web:

Tower of Hanoi - posted in CodingForums (http://www.codingforums.com/showthread.php?t=11237&page=3#post178220), DynamicDrive (http://www.dynamicdrive.com/dynamicindex12/hanoi.htm), Facebook (http://www.facebook.com/apps/application.php?id=264548538546) and MySpace (http://www.myspace.com/519493692).

SameGame - http://www.codingforums.com/showthread.php?s=&postid=123561#post123561

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum