↑ Return to Android Applications

Online Multiplayer Android Game

For about a year (2012-2013) I had a side project that is an Android turn-based projectile game. If you know Worms, or Gunbound, then you know exactly what I’m talking about. I thought this style of game was perfect for the mobile platform where you can take a quick turn, and then wait for an opponents move. In order to make this online game a reality, I had to build from scratch my own multiplayer server to help the clients (phones, tablets) communicate with each other.

First, I had to learn how Android’s Google Cloud Messaging worked. This is what would allow me to send push notifications directly to player’s devices so that they would know when it was their turn in a game. I set up a Java based GCM server using Google App Engine. Now I was able to send notifications to devices with various events.

Where was I going to store the data for each game? I couldn’t store it on each player’s device, as that would make keeping two devices in sync pretty difficult. Of course, the solution that made the most sense was to just have the game data stored in the cloud, and each device pull from that central database. So, I implemented an SQL database which held various pieces of data that was needed for the game to run. Player coordinates, who’s turn it is, the properties of their last shots, etc.

So now I had a GCM server which I could use to notify players of events, and a SQL database with game data stored in the cloud. How could I update the database from the Android devices? Android supports SQLite locally on the device, but there’s nothing in the Android API for accessing a database over the internet using an SQL variant. What I had to do was use PHP as a middle man to my database. In the Android game, I used HTTP to POST data to a PHP file located on my webserver, and then that PHP file wrote the values to the database that I needed. After writing new game data to the database, the PHP file would message the GCM server with the device ID that needed to be sent an Android notification that it was now their turn. When that device opened the game, they would automatically pull in the latest data from the SQL server in the same manner.

I essentially wrote my own API for talking to an SQL server remotely from an Android device. Here’s a picture of my whiteboard that illustrates this all a little more clearly.

2012-10-14 21.17.43

So at this point, I had an infrastructure in place for holding game data, and I had devices talking to one another. But what about the actual game itself? I used AndEngine, which is an open source 2D Android game engine. This included a physics engine and graphics engine for drawing objects to the screen.

All of my code for both the GCM server, PHP, and the actual game itself was version controlled using SVN and hosted by Springloops.

The game in it’s current state is 100% playable. It is more a proof of concept at this point that a finished product. Right now, I do have working online multiplayer up to 8 players for 4v4 action. There is wind that affects players shots, different maps, lives per team, and the plumbing is there for even more features that I didn’t get a chance to add. There is also a game lobby where all players can join and settings can be adjusted before the game begins. The graphics are awful and were meant to be placeholder.

I ultimately suspended this project just because I felt like I could never get this to a place where I was happy enough with the project to actually release it. Working full time left me with not as much time as I think is needed to really make a polished A+ quality game in today’s competitive marketplace. Overall, I learned a lot while working on this project even though I never released it. I learned about Google’s Cloud Messaging, Google App Engine, HTTP, SQL, PHP, game design, SVN, and how to best gather feedback from testers and take their suggestions and bug reports into account. Here are some screenshots of the game in it’s current state.

Splash Screen – when the game launches this is displayed while I load resources in the background
Screenshot_2013-08-28-23-40-03

Main Menu – shows all the games a player is currently in, and if it’s their turn or not.
Screenshot_2013-08-28-23-40-10

Game Lobby – this is shown before a game begins. Once all players are ready, the “Host” can start the game. Here, we can see by the “Waiting…” at the bottom that not all players are ready. “John” needs to mark that he’s ready. We can tell he’s not because the ‘R’ by his name is Red, not green. “Jared” is the host, shown by the ‘H’ next to his name.
Screenshot_2013-08-28-23-40-23

In Game Screenshot – 3v3 Game
Screenshot_2013-08-28-23-41-06

In Game Screenshot – a player takes 47 damage
Screenshot_2013-08-28-23-41-42

In Game Screenshot – Players can see a shot ‘replay’ when they open up the game. Here we see a replay of the last shot for 244 damage while we wait for “Evan” to take his turn.
Screenshot_2013-08-28-23-42-32

In Game Screenshot – There is a slider that shows all the players in up-coming turn order. The numbers seen here are “delay”, which represents how long it is until your next turn. Delay would be a number that is larger depending on how powerful of a weapon a player chose on the previous turn. This would be the downside of using a powerful weapon – your turn might be skipped the next time around!
Screenshot_2013-08-28-23-43-10