Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts

    Javascript Games, Baby!

    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!

    Code:
    <!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?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Ummm...you really *ARE* kidding, aren't you!?
    know of any cools ones?
    http://www.google.com/search?q=javas...x=&startPage=1
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by Old Pedant View Post
    Ummm...you really *ARE* kidding, aren't you!?
    Yup.

  • #4
    New Coder
    Join Date
    Dec 2009
    Posts
    82
    Thanks
    0
    Thanked 6 Times in 6 Posts

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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:

    http://www.juncojunction.com/juncoju...MazeCraze.html

    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,960
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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, DynamicDrive, Facebook and MySpace.

    SameGame - http://www.codingforums.com/showthre...561#post123561


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •