Create Multi-player games

You have always wanted to make games or apps that talk to other devices, now if you have followed the GameKit offered by Apple (available for a while) it allowed for connecting two or more iOS devices over the WiFi and Bluetooth to pair up and offer some form of gaming experience.

Being an old school gamer and growing up in a time when the internet was not common place and Google was no body's friend, I have not been a fan of multi-player games, the only multi-player that I was aware of was sticking in 2-4 joysticks into 8-bit consoles and then literally pushing the other just to get a win.

Then came the multi-player gaming with Nintendo GameBoy and DS, where there were WiFi games that two DS devices could connect and play. And now when we have mobile gaming, and many developers that look at easy to use frameworks find it difficult to get an option to include these functionalities.

MYDevelopers, a group of developers that were not even known have in the last 1-2 months made themselves known in the circles of CoronaSDK users as the developers that have brought the Ultimote, Profiler and now AutoLan. Before I dwelve into the product a bit further, I must add that they have produced some really wonderful code and techniques that have helped developers working with Corona to overcome the issues imposed by the on-screen simulator, to the extend that they have been able to offer tools in the sandbox that they were offered to provide low level tools for developers to boost their productivity.


So what is AutoLAN?
AutoLAN is the latest release from these talented developers, it allows for enabling Multiplayer gaming in your projects. It works on a simple principle, it creates a server on one device and the other can be the client. In fact several can be the client. Then there is Network Discovery, where you do not have to remember the IP Addresses and domain names of your network, in fact if you are even connected to the McDonalds or Starbucks WiFi with a friend, you can play your multi-player stuff and not have to deal with what the IP addresses of these locations were. This is in fact a very important factor in most applications that insist that the users type in the IP Addresses and more than often the poor user might have no clue about that.

It uses UDP for packet transmission, now if you know about the 7 layers of Networking, of which 3 are the physical layers of the copper and the wire, etc you will know that of the two TCP and UDP both have their pros and cons and UDP is the one generally used for Broadcasts and they are fast packets, fast because they can be unreliable, they may or may not reach their destination. Where are TCP is built for reliability and hence compromises on speed. AutoLAN is built on UDP for speed and uses TCP when the requirement is reliability.

Then there is the option of file transfers, devices connected on the same network can send/share files between the devices, which of course are paired in a client server mode, with at least one server to which several clients can be connected. Then there is the functionality of Flow Control, where the device can be notified of receiving a packet so that a multi-player app/game does not really end up sending or requesting a packet and thereby flooding the network. They have also added a wonderful feature of Priority Broadcasts, where some packets can be designated as priority, in a general sense, let's say 5/6 players pair up on an app and are playing Capture the flag in Quake Arena developed using CoronaSDK (one day we might have that kind of power from CoronaSDK, we can only be optimistic) There can be lag of some sort while the players and their locations get updated, This is the time where every device no matter the lag might want to be intimated that the flag has been captured by a particular team, Priority broadcasts can be used in such a situation, where thought the network is filled with the packets that keep updating and firing at the other players.

On a slightly more realistic front, these brilliant guys have harnessed the power of their AutoLAN library in a sample of multi-player pong. This might not seem like much at this point as we might have all seen better games than that of pong and even the versions that have so many more features. However the idea with this sample is not about Pong, but about how to have a multi-player version and still have the game synchronous between two devices. In fact they even wrote an article on how they have managed to have the multi-player pong synchronize so well. Well you cannot call it cheating, but they have used the reliability of the BOX2D based physics engine to provide synchrony between the two devices, so while they exchange the Paddle position between the two over the network, the pong ball is moved purely by physics which will be able to be replicated on the devices with equal precision. Whatever be the way, that is a brilliant sample that they have to showcase the library, now it is up to some really samrt developers to take that further and come up with a really amazing product built on AutoLAN.

There are host of other samples that take you through how to use this library.

So reading all of this, a thought might have surely come to your mind, All this networking stuff sounds scary and complicated, can I really use this library in my games? So I have to know about Networking before I use this in my multi-player game?

Here's how simple it is
local server = require "Server"
 server:start()

Now we need on the client
local client = require "Client"
 client:start()
 client:autoConnect()

Voila!! You have a connected client server, you can have several clients connect to the server, there are no limitations other than the device limitations or network limitations on the number of connections.

There are other options like PubNub that allow for multi-player support using their cloud based servers, but seems very complicated with API keys etc. I am sure that these clever guys can surely come up with an update sometime soon that will work not only on the local network but utilising the WWW / Internet, so you can actually play multi-player with friends across the globe in as much realtime as possible.

on a closing note, let's say you created an app that is used in a conference like WWDC where every other person has created a server on their device, and you want to connect to a particular server, what do you do? They have a wonderful and rich documentation with events that you as the developer can use, so it will be a simple case of adding a Runtime listener for the event "autoLanServerFound"

Runtime:addEventListener("autoLanServerFound", createListItem)

and the function / handler is defined as

local function createListItem(event)
  print ( event.serverIP )
 end

so if you have a couple of servers, it will start listing the IP Addresses of these to the console, in your app you might actually have this displayed in a list item or similar UI element.

Similarly you can also catch the event autoLanPlayerJoined on the server every time a player joins. It might be a good idea to store this value in a list/array so that it can be used to send messages to later.

Some simple commands that can be used with AutoLAN

server:setCustomBraodcast("This is the message to be send to clients not connected")

client:sendFile("Icon.png", system.ResourcesDirectory
The thing to note is that all file transfers are in the background, which means it is non-blocking which in plain English means that the app will not freeze while the transfers are taking place.

If you have had a look at PhotoSynch, one of our favourite app, one that we cannot live without, you could be soon building a similar app using this library.


Summary

This is a wonderful library, probably one that is worth a lot to many developers and it offers the features that were not available to date with CoronaSDK. Now the part of this that is exciting and interesting is that this offers something that was beyond a lot more. It can allow for *GASP* communication or multi-player gaming between not just iOS devices or Android Devices but between iOS and Android devices.
The other feature of this Library that makes it so lucrative is the price, priced at $9.99 it is a steal, I would recommend that you purchase this right now, before the developers re-consider and increase the prices of this library.

We were provided a version that was prior to the final version, which means that the library is going to be more awesome when you get to purchase it.


SUMMARY
Software : AutoLAN - (Lua based Library for CoronaSDK)
Version : 1.0
Publisher : M.Y. Developers
Website : http://www.mydevelopersgames.com/AutoLAN
Twitter : @
Platform : Mac OS X (10.6.x or higher) / Windows running CoronaSDK
Price : $9.99

you could follow us on Facebook by liking our page at
http://www.facebook.com/pages/ReviewMe/137640632964588

We will have a giveaway that will be slightly different than following us and RT'ing the message, so keep an eye out for that.

Comments