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.
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.
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)
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
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
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.
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
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
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.
Leave A Reply