I Made Asteroids

AsteroidI stayed home sick today, and made a little browser asteroids game on my laptop.  The cool part is, it doesn’t need Flash or any other plugin.  It’s all JavaScript.  The even cooler part is, I am still blissfully ignorant about JavaScript, I wrote the whole thing in Python, using Pyjamas.  I’ve tested it on Firefox and Safari, works great on both, and runs super smooth even with lots of asteroids.

It’s not much of a game, really, just classic Asteroids without even scores or keeping track of ships or much of anything but the basics.  But it’s only about 300 lines of Python, and it runs in any off the shelf browser.

I’ll try to add some polish to it and get the source up somewhere soon for anyone interested.  I’m pretty happy I managed to do all that in a day, plus a few hours on previous days getting Pyjamas set up.

Update (11/19): I uploaded the source code. It’s not the best code I’ve ever written, and it’s not commented at all, but now it’s a real project!  Sort of.

Update (11/20): Version 0.2 is now live, with sound effects, a score, and a different Canvas object that allows it to run in IE6.  It’s too slow to be playable in IE6, but at least it runs.

Tags: , , ,

14 Comments

  • Wes says:

    Nice..it’s always fun to have those days when you’re knocking problems down left and right.

  • Michael says:

    Compiles fine for me, but when i try to open it locally i get a popup that reads: “Space ImportError: undefined”.

  • tom says:

    This is so fun, I sent it to Shan for
    trial. Happy Turkey Day! Get well soooon!

  • Ogre says:

    Glad you liked it. From my server logs, I think you’re using Internet Explorer 8, is that right? It doesn’t run full speed in that browser, at least not when I tried it. Anything else, like Firefox or Google Chrome, works much better.

  • Michael says:

    actually, im running in firefox 3.5.2 on Ubuntu 9.10.

    I also tried on my home laptop, running the same FF and Ubuntu, same results.

  • wgw says:

    Great demo of pyjamas! I compiled it on my machine and ran it on a localhost apache server. I got one error:

    Module random at line 47 :
    /dev/urandom (or equivalent) not found
    random.py, line 789:
    _inst = Random()
    random.py, line 35:
    self.seed(x)
    random.py, line 47:
    a = long(_hexlify(_urandom(16)), 16)
    os.py, line 17:
    raise NotImplementedError(“/dev/urandom (or equivalent) not found”)

    This is no doubt a problem with my configuration of Apache (random.py runs fine under python).

    Othewise the sound code does not work under pyjd (predictably), but works directly as an html page –with same problem, plus no sound.

    Great lesson for me about how to use the canvas in pyjamas. Thanks!

  • Paul says:

    Cool! Sounds a little delayed on Chrome but playable.

    Try adding some gravity between the ship and the big asteroids, or maybe the UFOs that come out
    and shoot up the place like in the arcade version.

  • Alex says:

    Hi,

    Cool idea, but unfortunately it’s not running for me under the latest Firefox or Chrome. That is, clicking on the link at the Pyjamas page,

    http://pyjs.org/examples/Space.html

    results in an endless load time…

    And the Console in Firefox reveals the following error list:

    $pyjs.loaded_modules[t.module] is undefined
    [Break On This Error]

    … (typeof $pyjs['loaded_modules'][t['module']]['__track_lines__'] != ‘undefined’)…

    sys.2d…a7da.js (line 188)

    listener.onImageLoad is not a function
    [Break On This Error]

    listener['onImageLoad'](self);

    pyjama…75de.js (line 248)

    $pyjs.loaded_modules[t.module] is undefined
    [Break On This Error]

    … (typeof $pyjs['loaded_modules'][t['module']]['__track_lines__'] != ‘undefined’)…

    sys.2d…a7da.js (line 188)

    listener.onImageLoad is not a function
    [Break On This Error]

    listener['onImageLoad'](self);

    pyjama…75de.js (line 248)

    $pyjs.loaded_modules[t.module] is undefined
    [Break On This Error]

    … (typeof $pyjs['loaded_modules'][t['module']]['__track_lines__'] != ‘undefined’)…

    sys.2d…a7da.js (line 188)

    listener.onImageLoad is not a function
    [Break On This Error]

    listener['onImageLoad'](self);

    pyjama…75de.js (line 248)

    • Ogre says:

      While I have reproduced the issue you outlined, the version hosted on my site works as far as I can tell (I clicked it, I’m using Firefox, it worked). That version is here

      The version on the pyjamas site is not maintained by me, and I have no access to do so.

      • Alex says:

        Hi Ogre!

        Thanks for the quick response! Your version works fine for me too. I’ll send a post to pyjamas to fix it hopefully :)

      • Peter says:

        Hi,

        the version on the pyjs.org-website (version 0.1) now works again. Though, as I noticed today, the game on your website (version 0.2) even has sound. Wow, great! That would be worth an update on the pyjs.org site. Do you have any objections?

        Just saying, you can of course “access” the version on pyjs.org, and update it (i.e. on GitHub through a PullRequest). If you directly maintained it there that would be the greatest thing of all!
        Looking forward to seeing you there!?

  • Stu says:

    Hi… there seems to be some sort of weird wordpress error – there’s a load of errors at the top of the page like the ones below.

    Error example:
    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/tinyogre/rumsey.org/blog/wp-includes/class-wp.php on line 201

    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/tinyogre/rumsey.org/blog/wp-includes/class-wp.php on line 202

    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/tinyogre/rumsey.org/blog/wp-includes/class-wp.php on line 201

    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/tinyogre/rumsey.org/blog/wp-includes/class-wp.php on line 202

    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/tinyogre/rumsey.org/blog/wp-includes/class-wp.php on line 201

    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/tinyogre/rumsey.org/blog/wp-includes/class-wp.php on line 202

    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/tinyogre/rumsey.org/blog/wp-includes/class-wp.php on line 201

    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/tinyogre/rumsey.org/blog/wp-includes/class-wp.php on line 202

    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/tinyogre/rumsey.org/blog/wp-includes/class-wp.php on line 201

    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/tinyogre/rumsey.org/blog/wp-includes/class-wp.php on line 202

    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/tinyogre/rumsey.org/blog/wp-includes

    • Ogre says:

      Yeah it gets in a funky state every once in a while. I think it’s “fixed” now. I figured out how to disable the warning. That’s the PHP way, right?

  • Wayy cool! Some extremely valid points! I appreciate you penning this write-up
    plus the rest of the site is really good.

Leave a Reply