Android Game Programming by Example

Book description

Harness the power of the Android SDK by building three immersive and captivating games

  • Implement the critical main game loop and structure your games to enable an array of advanced features
  • Animate your characters with sprite sheets, add multiple scrolling parallax backgrounds, and implement genuinely tough, playable levels in your games
  • Build super-smooth 60 frames per second with the help of this easy-to-follow, projects-based guide

In Detail

Android gaming is a hot topic these days, but one of the few areas of technology that does not have an abundance of clear and useful documentation online. However, there is an ever-increasing demand for Android games.

This book will help you get up to speed with the essentials of game development with Android. The book begins by teaching you the setup of a game development environment on a fundamental level. Moving on, the book deals with concepts such as building a home screen UI, implementing game objects, and painting the scene at a fixed resolution. Gradually, it builds up to the implementation of a flexible and advanced game engine that uses OpenGL ES 2 for fast, smooth frame rates. This is achieved by starting with a simple game and gradually increasing the complexity of the three complete games built step by step. By the end of the book, you will have successfully built three exciting games over the course of three engrossing and insightful projects.

What You Will Learn

  • Build simple to advanced game engines for different types of game, with cool features such as sprite sheet character animation and scrolling parallax backgrounds
  • Design and implement genuinely challenging and playable levels
  • Implement the critical main game loop
  • Implement basic and advanced collision detection mechanics
  • Bring to life a challenging enemy AI
  • Make the math behind 2D rotation, velocity, and collisions simple
  • Run your game designs at 60 frames per second or better
  • Process multitouch screen input effectively and efficiently
  • Implement a multitude of other game features such as pickups, firing weapons, HUDs, generating and playing sound FX, scenery, level transition, high scores, and more
  • Implement a flexible and advanced game engine that uses OpenGL ES 2 for fast, smooth frame rates

Table of contents

  1. Android Game Programming by Example
    1. Table of Contents
    2. Android Game Programming by Example
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Player 1 UP
      1. A closer look at the games
        1. Tappy Defender
        2. Tough retro platformer
        3. Asteroids simulator
      2. Setting up your development environment
        1. Installing the JDK
        2. Installing Android Studio
      3. Summary
    9. 2. Tappy Defender – First Step
      1. Planning the first game
        1. Backstory
        2. The game mechanics
        3. Rules for the game
        4. The design
          1. Control
          2. Model
          3. View
          4. Design pattern reality check
        5. The game code structure
          1. The Android Activity lifecycle
        6. The Android Studio file structure
      2. Building the home screen
        1. Creating the project
          1. What we did
        2. Building the home screen UI
          1. What we did
        3. Coding the functionality
        4. Creating GameActivity
          1. What we did
        5. Configuring the AndroidManifest.xml file
          1. What we did
      3. Coding the game loop
        1. Building the view
          1. Creating a new class for the view
          2. What we did
          3. Structuring the class code
        2. The game activity
      4. The PlayerShip object
      5. Drawing the scene
        1. Plotting and drawing
        2. Drawing PlayerShip
          1. The Canvas and Paint objects
        3. Controlling the frame rate
      6. Deploying the game
        1. Debugging on an Android device
      7. Summary
    10. 3. Tappy Defender – Taking Flight
      1. Controlling the spaceship
        1. Detecting touches
        2. Adding boosters to the spaceship
        3. Detecting the screen resolution
      2. Building the enemies
        1. Designing the enemy
        2. Spawning the enemy
        3. Making the enemy think
      3. The thrill of flight – scrolling the background
      4. Things that go bump – collision detection
        1. Collision detection options
          1. Rectangle intersection
          2. Radius overlapping
          3. The crossing number algorithm
        2. Optimizations
          1. Multiple hitboxes
          2. Neighbor checking
        3. Best options for Tappy Defender
      5. Summary
    11. 4. Tappy Defender – Going Home
      1. Displaying a HUD
      2. Implementing the rules
      3. Ending the game
        1. Restarting the game
      4. Adding sound FX
        1. Generating the FX
        2. The SoundPool class
        3. Coding the sound FX
      5. Adding persistence
      6. Iteration
        1. Multiple different enemy graphics
        2. An exercise in balance
        3. Format time
        4. Handle the back button
      7. The finished game
      8. Summary
    12. 5. Platformer – Upgrading the Game Engine
      1. The game
        1. The backstory
        2. The game mechanics
        3. Rules for the game
      2. Upgrading the game engine
        1. The platform activity
        2. Locking the layout to landscape
        3. The PlatformView class
          1. The basic structure of PlatformView
          2. The GameObject class
          3. The view through a viewport
          4. Creating the levels
          5. The enhanced update method
          6. The enhanced draw method
      3. Summary
    13. 6. Platformer – Bob, Beeps, and Bumps
      1. The SoundManager class
      2. Introducing Bob
      3. Multiphase collision detection
      4. Player input
      5. Animating Bob
      6. Summary
    14. 7. Platformer – Guns, Life, Money, and the Enemy
      1. Ready aim fire
        1. Pickups
          1. The drone
          2. The guard
      2. Summary
    15. 8. Platformer – Putting It All Together
      1. Bullet collision detection
      2. Adding some fire tiles
      3. Eye candy
        1. The new platform tiles
        2. The new scenery objects
        3. Scrolling parallax backgrounds
        4. Pause menu with moveable viewport
        5. Levels and game rules
          1. Traveling between levels
        6. The level designs
          1. The cave
          2. The city
          3. The forest
          4. The mountains
          5. The HUD
      4. Summary
    16. 9. Asteroids at 60 FPS with OpenGL ES 2
      1. Asteroids simulator
        1. The game controls
        2. Rules for the game
      2. Introducing OpenGL ES 2
        1. Why use it and how does it work?
        2. What is neat about Version 2?
        3. How we will use OpenGL ES 2?
      3. Preparing OpenGL ES 2
        1. Locking the layout to landscape
        2. Activity
        3. The view
        4. A class to manage our game
        5. Managing simple shaders
        6. The game's main loop – the renderer
      4. Building an OpenGL-friendly, GameObject super class
      5. The spaceship
      6. Drawing at 60 + FPS
      7. Summary
    17. 10. Move and Draw with OpenGL ES 2
      1. Drawing a static game border
      2. Twinkling stars
      3. Bringing the spaceship to life
      4. Rapid fire bullets
      5. Reusing existing classes
        1. Adding the SoundManager class
        2. Adding the InputController class
      6. Drawing and moving the asteroids
      7. Scores and the HUD
        1. Adding control buttons
        2. Tally icons
        3. Life icons
          1. Declaring, initializing, and drawing the HUD objects
      8. Summary
    18. 11. Things That Go Bump – Part II
      1. Planning for collision detection
        1. Colliding with the border
          1. The first phase of border collision detection
        2. Colliding with an asteroid
          1. The crossing number
          2. The first phase and overview of asteroid collision detection
        3. The CollisionPackage class
          1. Adding collision packages to the objects and making them accessible
            1. Adding a collision package to the Bullet class
            2. Adding a collision package to the SpaceShip class
            3. Adding a collision package to the Asteroid class
        4. The CD class outline
          1. Implementing radius overlapping for asteroids and ships
          2. Implementing rectangle intersection for the border
      2. Performing the checks
        1. Helper methods
          1. Destroying a ship
          2. Destroying an asteroid
        2. Testing for collisions in update()
      3. Precise collision detection with the border
      4. Precise collision detection with an asteroid
      5. Finishing touches
      6. Summary
    19. Index

Product information

  • Title: Android Game Programming by Example
  • Author(s): John Horton
  • Release date: June 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781785280122