Factor Friends is a simple code example of a multiplayer iOS/Android game with Facebook integration, written using Corona SDK. Here is a brief overview of the project.
By Paul Moore, licensed under GPL v3.0. Artwork and sound courtesy of Morgan Long.
- root - Contains iOS icon images, launch images, licensing, configuration files, and other basic paraphernalia.
- aeslua - AESLUA source files.
- res - Resource files for artwork, music, and animation.
- game - Game Scene source files.
- menu - Menu Scene source files.
- connect - Connection Scene source files.
- result - GameOver Scene source files.
The game is a fairly simple game based around integer factorization. Because it depends on the GraphAPI for networking, it requires that you have a valid Facebook account. Don't worry, it does not post anything to any of your feeds.
- Open the App and click the 'log into Facebook' icon. The app is equipped with SSO, so it may or may not login directly.
- Once logged in, you should see a list of your Facebook friends. Click 'play' beside any one of them.
- If they have the app running and are in the menu screen, they will receive your game request. If they accept, you will begin the game together.
- The game alternates between one person creating integers from prime numbers, then the other person factoring that number.
- You get points by correctly factoring your buddy's integer.
- After x amount of turns, or a tie-breaker, the person with the most points wins.
And that is all there is to it!
Below is a list of tech that the app utilizes.
To avoid writing an application server from scratch (or integrating with one), Facebook was chosen since it is easy to use, and already has the existing necessary social structure.
The app requires no extended permissions, but does use the following information:
- Name
- Gender
- Facebook ID
- Friends (Facebook ID, Name, Profile Picture)
No login or account information is stored locally or remotely anywhere, aside from what may be stored (temporarily) by the Pubnub cloud servers.
Pubnub is used for communication between clients. I find it quite interesting, and usually enjoyable, to work with. Pubnub is pretty accessible and not platform dependant, it has many language bindings.
For all intents and purposes, the communication model is peer-to-peer. A user's Facebook ID is used to identify and connect to his or her Facebook friends.
- AESLUA v0.2 (Not currently used, but would be if a Pubnub cipher key is used).
- LuaBit v0.4 (Dependency for AESLUA).
- base64 (Needed if a Pubnub cipher key is used).
- pubnub-api (Any Pubnub API will do, however, my fork contains all the above dependencies).
These dependencies are included with the source distribution.
You can build so long as you have Corona SDK. Everything you need should be packed within this source distribution. Tested with Corona SDK Build 2012.799, on OSX 10.7.
If you do plan on building, make sure you update the bundle identifier in the build.settings if you plan on testing on a device.
The only bugs I am currently aware of are audio related bugs. For some reason, audio sometimes decides not to play. I've encoded the audio as 16-bit... etc etc etc .wav files but I'm still having troubles. I've monitored audio channels and looked for errors but I didn't find anything. At this point, I'm not sure if it is a Corona bug, Apple's OpenAL implementation, or my own doing.
I'm sorry if it ruins your experience, the music is quite catchy.
Have Fun!