Updated Asteroids

As part of prepping for c3dl’s upcoming release I had modified a demo that Peter Callaghan had made into a game.  Its a 3D take on the old asteroids game that is written entirely with JavaScript using webGL (If you want to play it you will need a webGL enabled browser… )  Instead of seeing your ship from top down, you see the space as if you are sitting on ship.  you can rotate around and shoot asteroids that are flying towards you (hit A and D to rotate left or right).  To hit an asteroid click on it.

Here is a screenshot:

My initial game was ok but had a few bugs in it.  I have since cleaned it up and added scoring.  I even added an end game model.  One snag that I really am stuck on has to do with sound.  Firstly I found out how easy it was to add sound using html5 audio tags… I thought it would be alot harder but apparently not.  I added an <audio> tag to my page, and in the js just loaded it and played.  about 5 lines of code in all… however I have hit a few snags and I am not sure why.

Firstly, I couldn’t get the audio to load in Webkit… I thought at first that it was because the format (ogg) was unsupported so I put in a bit of code to load an mp3 instead but that didn’t work either.  I’m going to have to probably play around with a simpler demo first.  I’m trying to find out if it needs to be enabled right now (like webGL) but so far have not found anything about having to enable it.

The other problem I ran into which I really really don’t understand is that on minefield, when I ran my game locally, it had no problem loading the audio file.  It played and didn’t have any trouble.  But when I uploaded my files to make them available to the web the sound broke… this makes no sense to me as to why this would be the case.  So far I have checked these issues:

  • relative path is correct (actually no path…the file is in same folder as html)
  • the permissions are correct
  • the transfer seems fine
  • files are in the directory

I really don’t understand why it should not work from my site while it worked locally.  I have checked it out with firebug and it seems the audio object is created so I’m not quite sure where to check next.  In any case perhaps I’ll take a page from my old school days and sleep on my bug…


2 responses to “Updated Asteroids

  1. I’m seeing this on all the C3DL demos (using minefield), I guess something changed in the spec and the recent nightlies adopted it already.

    ERROR: 0:1: ‘gl_FrontColor’ : undeclared identifier

    • yeah, c3dl is going to have a release soonish. Lots of updating going on behind the scenes but with WebGL still changing its been sort of crazy keeping things working as they break. Andor’s branch on github is probably the best place to get an “in progress” working version of the code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s