Tutorial to make Multiplayer Games in Windows Phone with AppWarp

We have extended Microsoft’s sample game Catapult War on Windows phone platform to elaborate the multiplayer cloud features of AppWarp Gaming Engine. Catapult wars is a two player game in which users have to hit each other with projectiles. The user who first successfully strikes the opponent five times is the winner.

dragging1 Tutorial to make Multiplayer Games in Windows Phone with AppWarp
Initilization
To initialize AppWarp Windows Phone Multiplayer SDK, you will need two parameters i.e. Apikey and pvtKey. To get these parameters, please login to AppHQ and register your game.

1
2
WarpClient.initialize(GlobalContext.API_KEY, GlobalContext.SECRET_KEY);
GlobalContext.warpClient = WarpClient.GetInstance();

After the initialization when a user clicks on the join button, the process of establishing connection to AppWarp Server will be started. It will take username of the game player (It’s recommended to use either Facebook login or Windows live login because duplicate usernames are not allowed on AppWarp)

1
2
GlobalContext.localUsername = txtUserName.Text;
WarpClient.GetInstance().Connect(GlobalContext.localUsername);

Send SHOT data to remote user
In this game when user fire catapult we need to send two parameter to remote user
1.Shot Strength
2.Shot Velocity
We will use TCP communication to send this data
1.Create Json Object Message Block

1
2
3
4
5
6
7
8
9
 public static byte[] buildSHOTMessageBytes(String ShotVelocity, String ShotAngle)
        {
            JObject moveObj = new JObject();
            moveObj.Add("sender", GlobalContext.localUsername);
            moveObj.Add("Type", "SHOT");
            moveObj.Add("ShotVelocity", ShotVelocity);
            moveObj.Add("ShotAngle", ShotAngle);
            return System.Text.Encoding.UTF8.GetBytes(moveObj.ToString());
        }

2.Send it by using SendUpdatePeers method

1
WarpClient.GetInstance().SendUpdatePeers(MoveMessage.buildSHOTMessageBytes(Catapult.ShotVelocity.ToString(), Catapult.ShotAngle.ToString()));

3.At recipient onUpdatePeersReceived method will be invoked and the same byte array message will be provide which can be parsed accordingly.

1
2
3
4
  public void onUpdatePeersReceived(UpdateEvent eventObj)
        {  
          byte[] message=eventObj.getUpdate();
        }

 Use room-properties to synchronize game.
Those parameters are common for all users and should be reflected by all users and we can manage them using room-Properties.

In the sample game, I have created the following room-Properties
1. Manage players’ scores

1
2
GlobalContext.tableProperties.Add("Player1Score", 0);
GlobalContext.tableProperties.Add("Player2Score", 0);

2. Manage some game specific parameters and these values should be same for all players

1
2
3
GlobalContext.tableProperties.Add("WindX", 0);
GlobalContext.tableProperties.Add("WindY", 0);
GlobalContext.tableProperties.Add("fireNumber", 1);

 
Source Code can be downloaded or viewed from our Git repo. If you have any questions or need any further assistance, please feel free to write us at support@shephertz.com.

twitter Tutorial to make Multiplayer Games in Windows Phone with AppWarpfacebook Tutorial to make Multiplayer Games in Windows Phone with AppWarpgoogle Tutorial to make Multiplayer Games in Windows Phone with AppWarplinkedin Tutorial to make Multiplayer Games in Windows Phone with AppWarppinterest Tutorial to make Multiplayer Games in Windows Phone with AppWarpreddit Tutorial to make Multiplayer Games in Windows Phone with AppWarpstumbleupon Tutorial to make Multiplayer Games in Windows Phone with AppWarptumblr Tutorial to make Multiplayer Games in Windows Phone with AppWarp

Leave a Reply

Your email address will not be published. Required fields are marked *


two + 6 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>