This article will give you an idea of how the new WaveEngine extension could be used in your existing WaveEngine game.

We will make use of an already finished game to integrate with Google Play, but you will require no more coding efforts at all to get Game Center up a running, other than what we are about to do for Google Play.

Let’s go into depth in the new Wave Social Engine extension.

Our goal is to integrate Google Play in SuperSquid, one of our quickStarters (https://github.com/WaveEngine/QuickStarters/tree/master/SuperSquid)

The game consists of a squid you control with the accelerometer and your goal is to catch as many stars as possible, avoiding evil octopuses and dodging obstacles.

It is a perfect example for adding a leaderboard panel and connect all your scores with your Google Play friends.

We will make the appropriate changes to this quickstarter to achieve our purpose.

Download and open the sln solution in Visual Studio.

Add a reference to the Social nuget package (https://www.nuget.org/packages/WaveEngine.Social/)

Let’s start adding some code, the first step is to instantiate the SocialService

private void InitializeAndRegisterSocialService() { var socialService = new SocialService(); socialService.Initialize(null); WaveServices.RegisterService(socialService); }

Next is to log in into Social Service.

To start SuperSquid you need to press the play button of the Main Screen, it will be at that time when the Google Play log in process would take place.

Modify the click event handler of the MainMenuScene play button and add the following code snipped.

play.Click += async (s, o) => { var logIn = await WaveServices.GetService<SocialService>().Login(); if(logIn) {

Once we are logged into Google Play we can start playing and get more stars.

SuperSquid has a GameOver screen displayed when the squid hits any obstacle, it will be at that point when we have to capture its current score and send it to the leaderboard.

Fortunately, we already have a block of code that is responsible for storing our high score so we just have to add a call to the appropriate social service method.

In the CreateScene() method you will see an “if” statement which checks whether the score achieved in the last run of the game is greater than the score you achieved in that moment.

Therefore it is only necessary to add one more line within this “if” statement to send our score to the leaderboard.

await WaveServices.GetService<SocialService>() .AddNewScore(LeaderboardCode, this.gameScene.CurrentScore);

The last code addition to achieve our purpose is to show the leaderboard panel, the most appropriate moment for this is right after submitting our new score to Google Play.

With this little line the Google Play leaderboards panel will show up with all associated leaderboards of our game.

await WaveServices.GetService<SocialService>().ShowAllLeaderboards();

This is all from the code point of view. It does not matter if you would end up using Google Play or Game Center, all of this code will be shared JIn the case you choose to go with Google Play there would still be three steps to follow.Register our game on Google Play

For this process we need to setup our app’s package name in the Visual Studio project’s properties.

Once this is done, enter your Google Play Developer Console account and check you have already created your Android application.

Remember to enter the same Application name and Package name you chose previously on the project’s properties.

Register a new Game Service associated with our game

In this step we need to create a new Game Service.

We provide its name and click continue.

Once completed we get our game appid, which is required to be in our game manifest.

<application android:icon="@drawable/Icon" android:label="SuperSquid"> <meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> </application>

As shown, the value of metadata com.google.android.gms.games.APP_ID references the app_id field defined in the resource file string.xml

<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_id">53593810874</string> </resources>

The next step is to link our game, again, providing the same package name.

We set up the package name and the name of our app.

Beware you will need to provide the “Signing certificate fingerprint” of the certificate used to sign your game’s apk, in SHA1 format.

Have a look at this article, if you need to find the appropriate SHA1 fingerprint of your game when you run it in debug mode, (https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/MD5_SHA1/)

The steps are as follows:

With this process we will link our app with the Game service.

SetUp a new Google Leaderboard

In this step we create and obtain the leaderboard ID to use in our game.

In our newly created service game, select the Leaderboard tab and add a new one.

Once created, the panel provides the Leaderboard code that we need to use in our game.

Then, in the piece of code that sends the new score you will be missing the LeaderboardCode. The corresponding value is in the ID column.

The SuperSquid quickstarter with all the modifications described in this article can be found in Github (https://github.com/WaveEngine/QuickStarters/tree/master/SuperSquid).

As always, if you get into troubles, you have questions or want more from us please post comments on this blog or in our forum.