I'm currently planning on building a HTML5/JavaScript game for the various platforms (Browser, iOS, Android, and WinMo7). I, obviously, would like there to be simple multiplayer (1v1, asynch), leaderboards, etc.

Finding a service that provides this for native applications is easy (Scoreloop, Gree, etc.) but I have yet to find one that allows access through JavaScript. So with that said, does such a service/platform exist or am I looking at creating my own (probably with node)?


Try Facebook. You have to host your game and everything, they just provide the actual playerbase and the social aspect, which are quite valuable. I believe that you still have to code up the leaderboards and all that, and I suggest Node.js + SQLite, it's a nice and robust solution for a simple project.

As for the achievement system, I'm not sure. I am not aware of any currently available HTML5 game engine that can handle these, as they (the achievements) can get quite game specific.

But, thankfully, they're not hard to implement, let me explain how I would do it...

A game can be considered a stream of events. Events, as in "player killed x", and "player gained new level", or "x killed y", you get the point. What you will need to do, to effectively implement achievements, is make an event system for your game.

To realize why, I must first explain what these are, although you probably already know all this because you're using HTML. Others might not, so I'll do it anyway.

An event system is consisted of events and listeners. You can implement listeners as functions that subscribe to certain events: each time an event fires, that function is executed, passing the objects and some other data to it as an argument.

I suggest that you have an EventManager that gets called on each game loop iteration (or less frequently), and holds all the listeners and other information.

If you want to listen to a certain event, you simply do this: eventManager.register("kill", function(killer, victim){...}).

This is, for example, how you would implement an achievement that requires the player to kill 100 enemies (it's a pretty bad achievement in terms of game design, but it's simple to implement).

var killed = function(killer, victim)
    if (!(killer instanceof Player)) //Only players can get this achievement.
        return false;

    ++ killer.n; //This is a Player object, usually, and it keeps track of how many times it has performed this action.

    if (killer.n == 100)
        killer.achievement("100done"); //The player should know how to handle this, no need to hardcode it.

eventManager.register("kill", killed);

//Later on, when the kill actually happens:

if (enemy.health <= 0)
    eventManager.fire("kill", [player, enemy]); //Implement this however you wish.

You could, of course, hardcode all of this in the actual game logic, but that would be awful and would get really messy. Also, you've built yourself a nice event system that you could use for many other situations too!

  • \$\begingroup\$ Thanks for the reply, Bane. I know about Facebook and plan to integrate with it, however I was looking for something that offered some (if not all) of the infrastructure required for leaderboards, achievements, etc. Facebook, sadly, does not offer that :( \$\endgroup\$ – Jason L. Jul 19 '12 at 19:07
  • \$\begingroup\$ Indeed, it doesn't. But, read the last sentence, you'll find what you're looking for! The key to these kinds of things (leaderboards etc) are databases. They help you with all kinds of useful queries for mixing and matching data! \$\endgroup\$ – jcora Jul 19 '12 at 19:31
  • 1
    \$\begingroup\$ Indeed, building and hosting my own database would be a solution however I was hoping to avoid doing that (save myself some work). Maybe I should of been more clear with that in my question :) \$\endgroup\$ – Jason L. Jul 19 '12 at 19:47
  • \$\begingroup\$ NoSQL is fairly simple, really, but as you've already got an answer, no point in learning it for now. \$\endgroup\$ – jcora Jul 19 '12 at 19:55
  • \$\begingroup\$ I'm already very familiar with node and mongo (and couch, for that matter). I was just being lazy but your answer convinced me it's not as bad as I was thinking. Also, for eventing I default to js-signals :) \$\endgroup\$ – Jason L. Jul 19 '12 at 21:54

I was able to find a social gaming service for JavaScript that offers most of what I'm looking for (everything but the actual multiplayer servers to use). It's called clay.io and can be found at http://clay.io/ :)

  • \$\begingroup\$ Damn, I just read this after I finished editing my answer and explaining how to make an event system... No matter, it might be useful for others. :) \$\endgroup\$ – jcora Jul 19 '12 at 19:54
  • \$\begingroup\$ You provided so much useful info in your updated answer it would be unfair for me to leave me as the answerer so I'll change that. Your answer even has me thinking ill build it myself since it really does seem so simple. Leaving this around for others who are looking for something similar. \$\endgroup\$ – Jason L. Jul 19 '12 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.