Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Powerup: send your Android game to the next level!

Powerup: send your Android game to the next level!

Every game has a story to tell. Whatever is your story, your players want long-lived games and gamifications and multiplayer features are the way! Send your Android, iOS or online games to the next level with Google Play Game Services.

Interactive presentation (for gifs and source code) is available at: https://evonove.slides.com/evonove/android-powerup
Application source code: https://github.com/palazzem/android-gaming

Emanuele Palazzetti

June 21, 2014
Tweet

More Decks by Emanuele Palazzetti

Other Decks in Programming

Transcript

  1. How much is valuable your story? This is the hard

    part When you've found your story, you'll surely need some tools... ...great tools!
  2. Google Play Game Service Some perks (using Google+ sign-in): Leaderboards

    Achievements management Progress storage Anti piracy
  3. Needed features Update our leaderboards Unlock some achievements Count incremental

    achievements Have a leaderboards Activity Have an achievements Activity
  4. Game Core @Override public void onEnteredScore(int requestedScore) { int finalScore

    = mHardMode ? requestedScore / 2 : requestedScore; mWinFragment.setFinalScore(finalScore); mWinFragment.setExplanation(mHardMode ? getString(R.string.hard_mode_explanation) : getString(R.string.easy_mode_explanation)); // check for achievements checkForAchievements(requestedScore, finalScore); // update leaderboards updateLeaderboards(finalScore); // push those accomplishments to the cloud, if signed in pushAccomplishments(); // switch to the exciting "you won" screen switchToFragment(mWinFragment); }
  5. Accomplishment Outbox class AccomplishmentsOutbox { boolean mPrimeAchievement = false; boolean

    mHumbleAchievement = false; boolean mLeetAchievement = false; boolean mArrogantAchievement = false; int mBoredSteps = 0; int mEasyModeScore = -1; int mHardModeScore = -1; boolean isEmpty() { return !mPrimeAchievement && !mHumbleAchievement && !mLeetAchievement && !mArrogantAchievement && mBoredSteps == 0 && mEasyModeScore < 0 && mHardModeScore < 0; } }
  6. Check for achievements void checkForAchievements(int requestedScore, int finalScore) { //

    Check if each condition is met; if so, unlock the corresponding // achievement. if (isPrime(finalScore)) { mOutbox.mPrimeAchievement = true; achievementToast("Prime score"); } if (requestedScore == 9999) { mOutbox.mArrogantAchievement = true; achievementToast("Arrogant! (requested maximum score)"); } if (requestedScore == 0) { mOutbox.mHumbleAchievement = true; achievementToast("Humble! (requested 0 score)"); } if (finalScore == 1337) { mOutbox.mLeetAchievement = true; achievementToast("Clairvoyant"); } // Accumulator for incremental achievements mOutbox.mBoredSteps++; }
  7. Update leaderboards void updateLeaderboards(int finalScore) { if (mHardMode && mOutbox.mHardModeScore

    < finalScore) { mOutbox.mHardModeScore = finalScore; } else if (!mHardMode && mOutbox.mEasyModeScore < finalScore) { mOutbox.mEasyModeScore = finalScore; } }
  8. Push game status void pushAccomplishments() { if (!isSignedIn()) { //

    can't push to the cloud, so save locally mOutbox.saveLocal(this); return; } if (mOutbox.mPrimeAchievement) { Games.Achievements.unlock(getApiClient(), API_KEY); mOutbox.mPrimeAchievement = false; } if (mOutbox.mArrogantAchievement) { Games.Achievements.unlock(getApiClient(), API_KEY); mOutbox.mArrogantAchievement = false; } if (mOutbox.mHumbleAchievement) { Games.Achievements.unlock(getApiClient(), API_KEY); mOutbox.mHumbleAchievement = false; } if (mOutbox.mLeetAchievement) { Games.Achievements.unlock(getApiClient(), API_KEY);
  9. Really? // Unlock an achievement Games.Achievements.unlock(getApiClient(), API_KEY); // Update a

    leaderboard Games.Leaderboards.submitScore(getApiClient(), API_KEY, SCORE); // Incremental achievements Games.Achievements.increment(getApiClient(), API_KEY, STEPS);
  10. Ask game status @Override public void onShowAchievementsRequested() { if (isSignedIn())

    { startActivityForResult( Games.Achievements.getAchievementsIntent(getApiClient()), REQUEST_CODE); } else { showAlert("Please sign in to view achievements"); } } @Override public void onShowLeaderboardsRequested() { if (isSignedIn()) { startActivityForResult( Games.Leaderboards.getAllLeaderboardsIntent(getApiClient()), REQUEST_CODE); } else { showAlert("Please sign in to view leaderboards"); } } Note: REQUEST_CODE is an arbitrary number used in whole app
  11. We must obtain app and achievements ID! <resources> <string name="app_id">ReplaceMe</string>

    <string name="achievement_prime">ReplaceMe</string> <string name="achievement_really_bored">ReplaceMe</string> <string name="achievement_bored">ReplaceMe</string> <string name="achievement_humble">ReplaceMe</string> <string name="achievement_arrogant">ReplaceMe</string> <string name="achievement_leet">ReplaceMe</string> <string name="leaderboard_easy">ReplaceMe</string> <string name="leaderboard_hard">ReplaceMe</string> </resources> ids.xml
  12. SHA1 fingerprint of your debug key keytool -v -list -keystore

    <debug_key_path> Where you can find your debug key: ~/.android/ [Drive]\Users\[Username]\.android\