Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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)?

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

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!

share|improve this answer
    
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 :( –  Jason L. Jul 19 '12 at 19:07
    
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! –  jco Jul 19 '12 at 19:31
1  
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 :) –  Jason L. Jul 19 '12 at 19:47
    
NoSQL is fairly simple, really, but as you've already got an answer, no point in learning it for now. –  jco Jul 19 '12 at 19:55
    
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 :) –  Jason L. Jul 19 '12 at 21:54
show 1 more comment

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/ :)

share|improve this answer
    
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. :) –  jco Jul 19 '12 at 19:54
    
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. –  Jason L. Jul 19 '12 at 21:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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