Posts Tagged ‘tutorial’

Firebase from Scratch, pt II: Diving In

Monday, September 5th, 2011 by larsan

In a series of posts we’ll do “Firebase From Scratch”, an introduction to Firebase and it’s concepts and ideas. Hopefully, reading this series should give you a firm grasp of what Firebase is and what it can do. Parts: 1 – 2

So, you want to write a multi-player game? And perhaps you’re considering Cubeia Firebase as your platform? Then we’ll take a good look at what you actually need to know, and need to do to get going. We’re going to keep it short, and then expand on the different items in later posts.

Client Language
You need a game client, and should decide what language or platform you’ll be using. If you want to deploy it to the web, perhaps flex would be suitable. If you want a heavier client, you should probably go for C++ or Java. For the rest of these posts we’ll assume you went the Flex / Flash track, but Firebase supports Flex and Flash, Java, C++ and C# so it is really your choice!

The Firebase Protocol
The client API of your choice comes with ready made command objects for a number of actions that are taken care of by Firebase, and that you don’t have to do yourself! They are taken care of by the platform, and include:

  • login / logout
  • join / leave game
  • watch / unwatch game
  • query / subscribe lobby
  • send action to game / service
  • etc…

In most cases, the Firebase commands are request / response. You will, for example, send a “login” command to the Firebase servers, and then wait for an answer which will be either a “yes” or a “no” (we’ll discuss Firebase and authentication / login later). The “send action to game” is how you communicate with your game, which is running inside Firebase, and for more on that, see below.

Your Protocol
The Firebase protocol takes care of many “generic” actions for you, but you will need to have a protocol specific to your game.These are the actions your players can make, such as:

  • fire weapon
  • move
  • place bet
  • do the macarena
  • etc…

the actions you actually need will be apparent when you start writing your game, but at this point you should figure out what form the commands will take. Firebase will treat your own commands as binary data, that is to say, you can use any format you want. Many will use XML or JSON which are widely supported in all languages. For larger projects though, we’d recommend you to look at protocol generation schemes such as Google’s Protobuf as it scales better and nicely separates your protocol from your code which is something that becomes important as the game grows in size. You can even use the protocol generation used by Firebase, called Styx; This generator takes a specification in XML and produces serialization factories and command objects in a variety of languages.

Server Language
The server code is the heart of your game. This is where most decisions will take place, where you keep track of the players, send notifications and much more. Normally all Firebase games are written in Java, but you can also write your server code in a number of script languages such as JavaScript or Ruby which is brilliant if you quickly want to prototype a game. Be aware though that the script languages are a bit slower, so if high performance is a must for you, you’ll have to go the Java route.

Building Server Code
How you build your client code is very much up to you and what IDE you’re using. But for the server side code we strongly recommend use Apache Maven for building, simply because there’s some neat plugins and tools already built for you to simplify your life. It is still your choice though and you can use anything from Ant to batch scripts.

Database
You probably want to store results and data somewhere. Firebase will not impose any choice on you and you’re free to use whatever data storage you like best. Firebase contains build in support for most relations databases, such as MySQL or Oracle, via JDBC and JPA, but you can equally well use column databases or simple text files, the choice is entirely up to you!

Ready. Set. Go!
So download what you need. If you went with the Flex/Java route you will need a Java SDK installed together with Apache Maven. Strictly speaking you don’t need an IDE, you could use a simple text editor, but normally you will want to install IDE:s such as Eclipse before going on. And with that done you should be ready to dive in head first in the traditional “hello world” tutorial on our wiki. Or if your feeling brave, the “quickstart extreme – not for the faint hearted“!

Next installment will look closer at the server game itself, its components and functions. Stay tuned!

Write a multiplayer game in 10 minutes or less!

Wednesday, February 10th, 2010 by larsan

As I was surfing along the other day it struck me that one of the coolest things about Firebase Community Edition is how incredibly fast you can get going. Do you think the title is a boast? Well, in a manner of speaking it is,  you see: we’re using Maven to build, and if you haven’t used Maven to build a Flex/Flash client before, Maven is going to start with downloading half of the Internet for you, and that will inevitably slow you down and may take a few minutes. But hear me! If you have used Maven before, and if you allow for the first time Maven will download the artifacts needed to compile the Firebase game and the Flex client, then I stand firm: you will have a Flex client and a Java server going in less than 10 minutes!

Do you want to get started on a multiplayer game really, really fast? Here’s two different ways:

  • The Extreme Quick Start – This hard-core, and Maven only, quick start will have you up in less than 5 minutes (excluding Maven download times). It does not however, send actual game actions between the client and the server, all you can do is join/leave tables and chat with other players… Excuse me? All you can do?! It’s completely awesome if you ask me.
  • The Beloved Hello World – This tutorial can be done with Maven and optionally Flexbuilder. It will explain along the way what happens, and it will also replace the Firebase standard chat with game actions (also chat) showing you how to communicate properly between game server and client. 10 minutes? Well, if you’re impatient and a fast reader, or if you do it twice you will most certainly beat the 10 minute mark.

If you ask me, and I’m obviously biased, this is extremely cool. Of course, this isn’t actually a game yet and there’s a lot more to learn before launching your own international success on Firebase, but hell, you want to write a game? Hop right to it!

Update: The commenting system seems to be behaving badly.  Even I can’t seem to comment at the moment. Please check the main blog for updates. I’ll be looking at switching blog system now…