TankWar has online mode again: This time on Opera Unite

December 2, 2009 – 6:45 pm Tags: , ,

You may recall an earlier post about TankWar, my 100% JavaScript cannons-game. Back when I wrote it, I included online play, but the server went down with a hard disk failure.

Now, I have rewritten the online mode - this time that part is also all JavaScript - continue reading to find out what makes it tick.

The original server

I wrote the original server for TankWar using Python and the Twisted library. Now, since I had nothing left, I had to reverse-engineer how the server used to work from the client’s code.

It proved to be a bit tricky, but eventually I succeeded

The new 100% JavaScript implementation

I decided I wanted to write the server as an Opera Unite application, and Opera was conveniently running a competition for Unite apps too.

The latest version of the application uses Bayeux as the protocol. It’s a straightforward JSON-based protocol for Comet, supported by the Dojo Foundation, and with client libraries available for both Dojo and jQuery.

I decided to put the Bayeux protocol related server code on GitHub under project JavaScript bayeux server. The code doesn’t support all of the Bayeux protocol yet, but it can be used to implement applications already as I have done. I plan to continue working on some new features for the library, but if you want to contribute, feel free.

I call the application itself TankWar on Unite. As mentioned, it uses Opera Unite as its base. I hadn’t developed Unite applications before, but it turned out to be a relatively simple job, thanks to the fact that Unite uses JavaScript with few custom APIs.

Unite applications also have the ability to keep persistent state, so it was perfect for a game where I needed to keep things together over multiple requests.

In closing

I’m planning on doing some more stuff for the game, such as improving the engine itself as it’s a little bit glitchy. Perhaps also improving the graphics, maybe by using bitmap sprites with canvas.

If you want to check out the Unite application’s source code, simply download it from the mentioned site and rename the file to .zip. It should at least serve as a good example on how to use the Bayeux server for writing your own Comet-based Unite apps.

The Bayeux server itself might also work with other JavaScript runtimes like Rhino. You would most likely need to implement a custom RhinoConnection object though, as I have only used it with Unite so far.

Share this:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • description
  • E-mail this story to a friend!
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • Technorati

RSS feed Subscribe to my RSS feed

  1. 5 Responses to “TankWar has online mode again: This time on Opera Unite”

  2. The guys at Opera Desktop QA was playing this game for over an hour today. (We were testing Unite, obviously.) It was a very fun game and a cool way to use Unite! Good work!

    We found some bugs, and hope you will find the time to fix them.

    * Game sometimes stops when a player is defeated (next turn assign to the defeated player?)

    * The red weapon’s fire trail is displayed with a too high trajectory for other players (though the explosion always hit the same spot, but the trajectory is out of sync for other players so they can’t properly prepare to be blasted to bits)

    * The bomber weapon is far to powerful! You can annihilate all opponents in one go.

    * Chat box need to be taller

    Also, the “play online” screen should explain how you invite your fiends to come and play with you. (Provide a direct link to join a game?)

    The Opera Desktop QA team is eagerly awaiting an update to this game. (For testing purposes, of course.)

    By Daniel on Dec 2, 2009

  3. Not sure if you were using 1.2 or 1.0, but:

    #1 should be fixed in 1.2, but I’ll try checking corner cases to be sure.
    #2 It gets messed up if your PC’s aren’t about equally fast. On the list of things to fix.
    #3 Intentional ;) You can reduce the amount of bomber ammo if you want.
    #4 1.2 has a bigger chat box. Planning on improving the UI more later though.

    I’ve been thinking of making some kind of a P2P solution to the online mode where it could display games from your friend’s PCs or such. Did not think of displaying instructions for a link - I think that would be a good improvement until I can come up with a more “high tech” solution.

    Thanks!

    By Jani Hartikainen on Dec 2, 2009

  4. Thanks for your reply. We’ve been playing 1.2 from unite.opera.com.

    #1 It happen at least four times while we were playing. Four players. Usually when the first player was knocked out.
    #4 It isn’t big enough for four friends to threaten and insult each other. :)

    The default Unite applications all provides links for you to share with friends. Because it’s easy to understand for all parties. Direct-to-game links could just assign people random player names and get them joined in quickly.

    By Daniel on Dec 2, 2009

  5. I’ve also had games were it’s no in-game player’s turn after one player has been defated.

    A simple timeout if a player don’t do anything would help the game recover.

    By Tom E. on Dec 2, 2009

  6. Congrats on winning the Opera Unite contest mate!

    You should release the source for others to see.
    (My bad attempt at a joke… since it is client-side javascript =P)

    By CodeJustin on Dec 7, 2009

Post a Comment