Quantcast
Channel: Indie Flash Blog » async
Viewing all articles
Browse latest Browse all 4

How to Create an Asynchronous Multiplayer Game

$
0
0

There’s no doubting the fact that “asynchronous” multiplayer gameplay, or the ability to play games one turn per session over the course of several days, is the new hot trend in mobile gaming. Many of the top multiplayer games are asynchronous, including the popular Words with Friends (a one-move-at-a-time implementation of Scrabble) and Draw Something (a unique take on Pictionary that was recently bought by Zynga for 200 million).

When my cross-platform multiplayer game, Hero Mages, launched on iOS, I thought people would be excited by the ability to play live online battles with their friends playing on PC’s or Android devices. To my surprise, the overwhelming feedback I got was “this game would totally rock if only it had async multiplayer!”

As most Hero Mages players know, I’m not one to disappoint- so I immediately restructured my priorities for the next game update to include asynchronous multiplayer. Having never programmed “async multiplayer” before, I figured I’d start like I always do: with a Google search. The returns for ” how to program async multiplayer” weren’t very helpful: I found articles talking about how async is awesome and learned about a great selection of titles that support it- but the key “how to” part was strangely absent. It then occurred to me “This would be a really great resource for game developers”, so I’ve decided to chronicle my development of async multiplayer for Hero Mages here on IndieFlashBlog.com so that we can all benefit from what I hope will grow into a helpful “how to” series of articles.

Hero Mages is built using Adobe Flash, so my program code examples will be in ActionScript 3. The design and mechanics of async multiplayer, however, are applicable for any language.

Learn from the Masters

One of the best ways to learn how to program something new is to study an application that successfully achieves your desired result. My goal is to achieve asynchronous multiplayer gameplay for my fantasy themed turn-based tactical strategy game, Hero Mages. It just so happens there’s a similar game to Hero Mages on the App Store with a terrific implementation of async gameplay: Hero Academy by Robot Entertainment. So, I’ve spent some time the past couple weeks playing the game (what better way to do research) and I’ve got to give the developers serious props: their integration of social media such as Facebook and Twitter tied in with a very effective async multiplayer user interface does a very effective job at solving the “isolated community” dilemma one such as myself might experience in a “live online” multiplayer game.

Hero Academy Game Play

Multiplayer game list in Hero Academy

Here’s an overview of the async multiplayer in Hero Academy:

  1. Automatic login to servers upon launching game
  2. Invite/challenge players via Facebook and Twitter
  3. Option to create a new game or find a random opponent
    1. If player creates a new game, it gets added to an internal game list and waits for opponent to join
    2. If player opts to join game, a random game on the internal game list is selected and the player is connected. The joining player gets the first turn.
  4. Player can make up to 5 actions during their turn with the option to undo any or all of their choices before submitting their final commands.
  5. Once turn is submitted, database record of game is updated with new game state and a “Push” notification is sent to the opponent, indicating to them that it’s now their turn
  6. Opponent has 24 hours to complete their turn or the player can declare them as forfeit
  7. Player has the option to take turns in their next active game or return to their personal “Game list” which allows them to load any played game. Games are labeled with opponent, creation date, last move time, and status: victory, defeat, waiting for turn, ready to attack

Special Considerations for Hero Mages

Experimenting with Hero Academy provided a lot of insight into user experience of async multiplayer, but Hero Mages will need some specific considerations given its unique play mechanics:

  1. Hero Academy leverages an undo system which is great for async because players can experiment different move combinations before submitting their final choice. This works for Hero Academy because all damage is a fixed amount. Damage in Hero Mages, however, is calculated via dice rolls. Allowing an undo option isn’t feasible because it would affect a key play mechanic: chance.
  2. Hero Academy does not support live multiplayer. All of the moves and even player chat are communicated via database updates to the recorded game state. While it’s possible to play a game of Hero Academy with someone in the same room, the experience isn’t optimal because you have to wait for push notifications to go through and re-watch the animations your opponent already made when he commanded his units. An improvement to the system that would work well for Hero Mages would be the ability to restore a “live” game connection when both players are online- allowing you to see your opponents moves and communications being made in real-time.

How-to Create Async Multiplayer Development Outline

After  studying the user interface of Hero  Academy and carefully considering the special needs for Hero Mages, I came up with the following  steps that would be necessary to implement asynchronous multiplayer in my game:

  1. Create  a way to save the game state to an online database
  2. Write  a database query that loads a list of the player’s games and allows player to  load and restore a game session by clicking on an item in the list
  3. Upon  loading a game session, check to see if the session is currently available for  “live” play. If so, join the session in progress to connect with  opponents currently online. If not, create a “live” game room and  load the session.
  4. Devise  a way to replay any animations player did not “see” since their last  time playing the game session
  5. During  actual game play, write updates to the stored game state in the database each  time player issues an order (this differs from Hero Academy where you would wait until the end turn button is pressed  to update the database). By writing continuous, smaller updates to database  less bandwidth is used and the async-to-live play transition can be seamlessly  achieved.
  6. Find  a way to transition real-time gameplay elements (turn timer, drop timer, game  duration clock, AI turn controller) to async (unique challenge for Hero Mages, not applicable to all async  games)
  7. Design  a user interface for viewing and joining async multiplayer games
  8. Create  a match-making system that allows player to pick their army preferences,  preferred opponent type, etc. and matches player to games with available  opponents in database
  9. When  a game turn is complete, send a notification to next opponent via email or  device push notification indicating that it is now their turn to play

Async Game List UI Mockup for Hero Mages

Coming Next

Stay tuned for the next article in “How to Create an Asynchronous Multiplayer Game” where I’ll discuss saving game states to the online database.


Viewing all articles
Browse latest Browse all 4

Trending Articles