Can you beat my score?

App Inventor and the Google Game Services Google Game Services


How to use the Google Game Services Google Game Services with App Inventor

Create great game experiences with Google Play game services. Add achievements, leaderboards, and real-time multiplayer to your mobile and web games, and let players share their gaming experience with friends.

The example app Random Score Game presented here offers the following features:

You can purchase the example app Random Score Game including the used HTML and JavaScript files, see details below. Note: You will need a webserver to store these HTML and JavaScript files for your users.

Preparation

The first step is to set up Play Game Services with the Google Play Developer Console to get a client id and app id. In the Google Play Game Service settings I defined one leaderboard for the highscore list.
Note: You have to set up your game as web app and not as Android app!

Overview: How everything works

For the Google+ login and sharing a post via Google+ I used a webviewer and the JavaScript API. This example helped me to set up a HTML page together with some JavaScript files which take care about login/logout and sharing.

To get information about the current player (name and avatar icon), to post a score to the leaderboard (highscore list) and to read the highscore list I used the web component and the REST API. Also this information about Sharing interactive posts was very helpful.

It's also very easy to add achievements, but I did not play around with this feature.

To display the highscore list, I used a jQuery Mobile thumbnail button list, see also my alternative listpicker example.

App Inventor Blocks

Get Information about the Player

Retrieve the Player ressource for the currently authenticated user.


If successful, this response will be returned (JSON format)

        {
          "kind": "games#player",
          "playerId": string,
          "displayName": string,
          "avatarImageUrl": string
        }
      

Submit the Score to the Leaderboard after Game Over

Submits a score to the specified leaderboard.


If successful, this response will be returned (JSON format):

        {
          "kind": "games#playerScoreResponse",
          "beatenScoreTimeSpans": [
            string
          ],
          "unbeatenScores": [
            {
              "kind": "games#playerScore",
              "timeSpan": string,
              "score": long,
              "formattedScore": string,
              "scoreTag": string
            }
          ],
          "formattedScore": string,
          "leaderboardId": string,
          "scoreTag": string
        }
      

List Highscores

Lists the scores in a leaderboard, starting from the top.


If successful, this response will be returned (JSON format):

        {
          "kind": "games#leaderboardScores",
          "nextPageToken": string,
          "prevPageToken": string,
          "numScores": long,
          "playerScore": {
            "kind": "games#leaderboardEntry",
            "player": players Resource,
            "scoreRank": long,
            "formattedScoreRank": string,
            "scoreValue": long,
            "formattedScore": string,
            "timeSpan": string,
            "writeTimestampMillis": long,
            "scoreTag": string
          },
          "items": [
            {
              "kind": "games#leaderboardEntry",
              "player": players Resource,
              "scoreRank": long,
              "formattedScoreRank": string,
              "scoreValue": long,
              "formattedScore": string,
              "timeSpan": string,
              "writeTimestampMillis": long,
              "scoreTag": string
            }
          ]
        }
      

There is support for daily, weekly and all-time high scores. In the example I just use the all-time highscore.

Blocks Overview


Do you need help with your App Inventor project?

I can help you: for one hour I charge 25 USD.
Please contact me at info [at] puravidaapps [dot] com for details!
For questions about App Inventor, please use the App Inventor forum. Thank you.

Screenshot

Login


If the player wants to post his score to the public leaderboard and also wants to view the public leaderboard (highscore list), he needs to select "Public" in the permission dialog: "Make your game activity available via Google, visible to: Public"

Game Services


Google+ Post


After clicking onto the link in Google+, the user will be redirected to here.

Questions and Answers

Q1: I'm getting the following error after trying to login: "Error:invalid_client no registered origin."?
A: You have to set up your game as web app in the Google Play Developer Console and not as Android app!

Test

Tested successfully on HTC Desire running Android 2.2 and Samsung Galaxy Tab 10.1N running Android 3.2.

Download

You can test this functionality with the Random Score Game, which is available for download here: Download apk file

Buy the source code for App Inventor


You can buy the source code of this project.
With your payment you accept the terms and conditions below.

Payment options

1. Paypal

Please transfer 10 USD via Paypal.

2. Bitcoin

After having received your payment I will be happy to send the source code to you.
Thank you! Taifun


Please check your spam folder in case you did not receive the example!
I usually will send the project not later than 24 hours after having received your payment.

 

Terms and Conditions

Back to top of page ...


Home | Snippets | Tutorials | Extensions | News | Forums | Links | Search | Contact