万本电子书0元读

万本电子书0元读

顶部广告

Android: Game Programming电子书

售       价:¥

6人正在读 | 0人评论 9.8

作       者:John Horton,Raul Portales,

出  版  社:Packt Publishing

出版时间:2016-09-01

字       数:984.9万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Extend your game development skills by harnessing the power of Android SDK About This Book Gain the knowledge to design and build highly interactive and amazing games for your phone and tablet from scratch Create games that run at super-smooth 60 frames per second with the help of these easy-to-follow projects Understand the internals of a game engine by building one and seeing the reasoning behind each of the components Who This Book Is For If you are completely new to Java, Android, or game programming, this book is for you. If you want to publish Android games for fun or for business and are not sure where to start, then this book will show you what to do, step by step, from the start. What You Will Learn Set up an efficient, professional game development environment in Android Studio Explore object-oriented programming (OOP) and design scalable, reliable, and well-written Java games or apps on almost any Android device Build simple to advanced game engines for different types of game, with cool features such as sprite sheet character animation and scrolling parallax backgrounds Implement basic and advanced collision detection mechanics Process multitouch screen input effectively and efficiently Implement a flexible and advanced game engine that uses OpenGL ES 2 to ensure fast, smooth frame rates Use animations and particle systems to provide a rich experience Create beautiful, responsive, and reusable UIs by taking advantage of the Android SDK Integrate Google Play Services to provide achievements and leaderboards to the players In Detail Gaming has historically been a strong driver of technology, whether we're talking about hardware or software performance, the variety of input methods, or graphics support, and the Android game platform is no different. Android is a mature, yet still growing, platform that many game developers have embraced as it provides tools, APIs, and services to help bootstrap Android projects and ensure their success, many of which are specially designed to help game developers. Since Android uses one of the most popular programming languages, Java, as the primary language to build apps of all types, you will start this course by first obtaining a solid grasp of the Java language and its foundation APIs. This will improve your chances of succeeding as an Android app developer. We will show you how to get your Android development environment set up and you will soon have your first working game. The course covers all the aspects of game development through various engrossing and insightful game projects. You will learn all about frame-by-frame animations and resource animations using a space shooter game, create beautiful and responsive menus and dialogs, and explore the different options to play sound effects and music in Android. You will also learn the basics of creating a particle system and will see how to use the Leonids library. By the end of the course, you will be able to configure and use Google Play Services on the developer console and port your game to the big screen. This Learning Path combines some of the best that Packt has to offer in one complete, curated package. It includes content from the following Packt products: Learning Java by Building Android Games by John Horton Android Game Programming by Example by John Horton Mastering Android Game Development by Raul Portales Style and approach This course is a step-by-step guide where you will learn to build Android games from scratch. It takes a practical approach where each project is a game. It starts off with simple arcade games, and then gradually the complexity of the games keep on increasing as you uncover the new and advanced tools that Android offers.
目录展开

Android: Game Programming

Table of Contents

Android: Game Programming

Android: Game Programming

Credits

Preface

What this learning path covers

What you need for this learning path

Who this learning path is for

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

Questions

1. Module 1

1. Why Java, Android, and Games?

Is this book for me?

If you just want to learn pure Java

If Android is your focus

Where this book will take you

Why build games to learn to program?

Why Android and Java?

Android is the fastest evolving and growing OS ever

Android developers have great prospects

Android is open source

Java is here to stay

Java is not just for Android

Java is fast and easy to use

A summary of Java and Android

Setting up our development environment

Installing the JDK

Android Studio

Installing Android Studio

Summary

2. Getting Started with Android

Our first game project

Preparing Android Studio

Building the project

Exploring Android Studio

Using the Android Studio visual designer

Android UI types

TextView

Layout elements

ImageView widgets

ButtonView

Using the sample code

Making our game menu

Structuring our code for Android

Life cycle phases – what we need to know

Life cycle phases – what we need to do

Dividing our game into activities

Our first look at Java

Cleaning up our code

Building and installing our game

Emulators and devices

Creating an emulator

Running the emulator

Running our game on the emulator

Building our game

Installing the setup to a device

Future projects

Self-test questions

Summary

3. Speaking Java – Your First Game

Java syntax

The compiler

Making code clear with comments

Storing data and using it with variables

Types of variables

Reference types

Declaration

Initialization

Changing variables with operators

Expressing yourself in Java

Math game – asking a question

Creating the new game activity

Laying out the game screen UI

Coding a question in Java

Linking our game from the main menu

Decisions in Java

More operators

Decision 1 – If they come over the bridge, shoot them

Decision 2 – Else, do this

Switching to make decisions

Math game – getting and checking the answer

Self-test questions

Summary

4. Discovering Loops and Methods

Looping with loops

While loops

Breaking out of a loop

The continue keyword

Do-while loops

For loops

Random numbers in Java

Methods

The structure of a method

Modifier

Return type

Name of a method

Parameters

Getting things done in the method body

Using methods

A working method

Exploring method overloading

Enhancing our math game

Enhancing the UI

The new Java code

Amending GameActivity

The methods

The setQuestion method

The updateScoreAndLevel method

The isCorrect method

Calling our new methods

Finishing touches

Going full screen and locking orientation

Adding a custom image (instead of the Android icon)

Self-test questions

Summary

5. Gaming and Java Essentials

Java arrays – an array of variables

Arrays are objects

A simple example of an array

Getting dynamic with arrays

Dynamic array example

Entering the nth dimension with arrays

An example of a multidimensional array

Array-out-of-bounds exceptions

Timing with threads

A simple thread timer example with the Handler class

Beeps n buzzes – Android sound

Creating sound FX

Playing sounds in Android

Life after destruction – persistence

An example of persistence

The memory game

Phase 1 – the UI and the basics

Phase 2 – preparing our variables and presenting the pattern

Phase 3 – the player's response

Phase 4 – preserving the high score

Animating our game

UI animation in Android

Phase 5 – animating the UI

Self-test questions

Summary

6. OOP – Using Other People's Hard Work

What is OOP?

Why do it like this?

Our first class and first object

Basic classes

More things we can do with our first class

Encapsulation

Controlling the use of classes with access modifiers

Class access in a nutshell

Controlling the use of variables with access modifiers

Variable access in a nutshell

Methods have access modifiers too

Method access in a nutshell

Accessing private variables with the getter and setter methods

Setting up our objects with constructors

Variables revisited

The stack and the heap

A quick break to throw out the trash

Access, scope, this, static, and constructors demo

A quick summary on stack and heap

Inheritance

An example of inheritance

Polymorphism

Abstract classes

Interfaces

More about OOP and classes

Inner classes

Self-test questions

Summary

7. Retro Squash Game

Drawing with Android Canvas

The Android coordinate system

Animating our pixels

Getting started with Canvas and Paint

Android Canvas demo app

Detecting touches on the screen

Preparing to make the retro squash game

The design of the game

The UI

Physics

The structure of the code

The four implementation phases in detail

Phase 1 – MainActivity and onCreate

Phase 1 code explained

Phase 2 – SquashCourtView part 1

Phase 2 code explained

Phase 3 – SquashCourtView part 2

Phase 3 code explained

Phase 4 – Remaining lifecycle methods

Good object-oriented design

Self-test questions

Summary

8. The Snake Game

Game design

The coordinate system

Keeping track of the snake segments

Detecting collisions

Drawing the snake

The code structure

MainActivity

GameActivity

Tidying up onCreate

Animation, sprite sheets, and the Snake home screen

Animating with sprite sheets

Implementing the Snake home screen

Implementing the Snake game activity

Enhancing the game

Self-test questions

Summary

9. Making Your Game the Next Big Thing

How to publish your app

Marketing your app

Adding leaderboards and achievements

Planning the Snake achievements

Step-by-step leaderboards and achievements

Installing the Google Play Services API on your PC

Configuring the Google Play developer console

Implementing the leaderboard in the Google Play developer console

Implementing the achievements in the Google Play developer console

Setting up the Snake project ready for implementation

Implementing the player's sign-in, achievements, and leaderboard buttons

Implementing the leaderboards in code

Implementing the achievements in code

Uploading the updated Snake game to Google Play

What next?

Getting a programmer's job

Building bigger and better games

Self-test questions

Summary

A. Self-test Questions and Answers

Chapter 2

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Chapter 9

2. Module 2

1. Player 1 UP

A closer look at the games

Tappy Defender

Tough retro platformer

Asteroids simulator

Setting up your development environment

Installing the JDK

Installing Android Studio

Summary

2. Tappy Defender – First Step

Planning the first game

Backstory

The game mechanics

Rules for the game

The design

Control

Model

View

Design pattern reality check

The game code structure

The Android Activity lifecycle

The Android Studio file structure

Building the home screen

Creating the project

What we did

Building the home screen UI

What we did

Coding the functionality

Creating GameActivity

What we did

Configuring the AndroidManifest.xml file

What we did

Coding the game loop

Building the view

Creating a new class for the view

What we did

Structuring the class code

The game activity

The PlayerShip object

Drawing the scene

Plotting and drawing

Drawing PlayerShip

The Canvas and Paint objects

Controlling the frame rate

Deploying the game

Debugging on an Android device

Summary

3. Tappy Defender – Taking Flight

Controlling the spaceship

Detecting touches

Adding boosters to the spaceship

Detecting the screen resolution

Building the enemies

Designing the enemy

Spawning the enemy

Making the enemy think

The thrill of flight – scrolling the background

Things that go bump – collision detection

Collision detection options

Rectangle intersection

Radius overlapping

The crossing number algorithm

Optimizations

Multiple hitboxes

Neighbor checking

Best options for Tappy Defender

Summary

4. Tappy Defender – Going Home

Displaying a HUD

Implementing the rules

Ending the game

Restarting the game

Adding sound FX

Generating the FX

The SoundPool class

Coding the sound FX

Adding persistence

Iteration

Multiple different enemy graphics

An exercise in balance

Format time

Handle the back button

The finished game

Summary

5. Platformer – Upgrading the Game Engine

The game

The backstory

The game mechanics

Rules for the game

Upgrading the game engine

The platform activity

Locking the layout to landscape

The PlatformView class

The basic structure of PlatformView

The GameObject class

The view through a viewport

Creating the levels

The enhanced update method

The enhanced draw method

Summary

6. Platformer – Bob, Beeps, and Bumps

The SoundManager class

Introducing Bob

Multiphase collision detection

Player input

Animating Bob

Summary

7. Platformer – Guns, Life, Money, and the Enemy

Ready aim fire

Pickups

The drone

The guard

Summary

8. Platformer – Putting It All Together

Bullet collision detection

Adding some fire tiles

Eye candy

The new platform tiles

The new scenery objects

Scrolling parallax backgrounds

Pause menu with moveable viewport

Levels and game rules

Traveling between levels

The level designs

The cave

The city

The forest

The mountains

The HUD

Summary

9. Asteroids at 60 FPS with OpenGL ES 2

Asteroids simulator

The game controls

Rules for the game

Introducing OpenGL ES 2

Why use it and how does it work?

What is neat about Version 2?

How we will use OpenGL ES 2?

Preparing OpenGL ES 2

Locking the layout to landscape

Activity

The view

A class to manage our game

Managing simple shaders

The game's main loop – the renderer

Building an OpenGL-friendly, GameObject super class

The spaceship

Drawing at 60 + FPS

Summary

10. Move and Draw with OpenGL ES 2

Drawing a static game border

Twinkling stars

Bringing the spaceship to life

Rapid fire bullets

Reusing existing classes

Adding the SoundManager class

Adding the InputController class

Drawing and moving the asteroids

Scores and the HUD

Adding control buttons

Tally icons

Life icons

Declaring, initializing, and drawing the HUD objects

Summary

11. Things That Go Bump – Part II

Planning for collision detection

Colliding with the border

The first phase of border collision detection

Colliding with an asteroid

The crossing number

The first phase and overview of asteroid collision detection

The CollisionPackage class

Adding collision packages to the objects and making them accessible

Adding a collision package to the Bullet class

Adding a collision package to the SpaceShip class

Adding a collision package to the Asteroid class

The CD class outline

Implementing radius overlapping for asteroids and ships

Implementing rectangle intersection for the border

Performing the checks

Helper methods

Destroying a ship

Destroying an asteroid

Testing for collisions in update()

Precise collision detection with the border

Precise collision detection with an asteroid

Finishing touches

Summary

3. Module 3

1. Setting Up the Project

The right tool for the right game

Do you want to use 3D?

Do you want to use physics?

Do you want to use Java?

Pros of building games with the Android SDK

Cons of building games with the Android SDK

I want the Android SDK!

The project – YASS (Yet Another Space Shooter)

Activities and Fragments

Project setup

Creating the stub project

Cleaning up

Choosing an orientation

Dealing with aspect ratios

Game architecture

GameEngine and GameObjects

Starting a game

Stopping a game

Managing game objects

UpdateThread

DrawThread

User input

Putting everything together

Moving forward with the example

Handling the back key

Honoring the lifecycle

Using as much screen as we can

Before Android 4.4 – almost fullscreen

Android 4.4 and beyond – immersive mode

Putting fullscreen together

Good practices for game developers

Object pools

Avoiding enhanced loop syntax in lists

Precreating objects

Accessing variables directly

Being careful with floating points

Performance myths – avoid interfaces

Summary

2. Managing User Input

The InputController base class

The Player object

Displaying a spaceship

Firing bullets

The Bullet game object

The most basic virtual keypad

Limitations and problems

Creating a virtual joystick

General considerations and improvements

Physical controllers

Handling MotionEvents

Handling KeyEvents

Detecting gamepads

Sensors and InputControllers

Selecting control modes

Summary

3. Into the Draw Thread

Using GameView

The GameView interface

StandardGameView

SurfaceGameView

Updating GameEngine

Updating the game layout

Improving DrawThread

Sprites

Updating the spaceship and bullets

Adding a frames-per-second (fps) counter

Spawning enemies – the GameController

Procedural/random

Deterministic/static

Hybrid approach

Our approach

The asteroids

More on the transformation matrix

Occlusion culling

Parallax backgrounds

Multiple backgrounds

Layers

Summary

4. Collision Detection

Detecting collisions

Who can collide?

Updating GameEngine

Handling collisions

Rectangular bodies

Adding visual feedback

Pros and cons

Circular bodies

Adding visual feedback

Pros and cons

Mixed collision detection

Adding visual feedback

Other options for shapes

Optimization

Spatial partitioning and QuadTree

Duplicated collisions

Summary

5. Particle Systems

General concepts

Particles

ParticleSystem

Initializers

Modifiers

Composite GameObjects and GameEngine

Making good particle systems

One shot

Asteroid explosions

Spaceship explosions

Emitters

Asteroid trails

The spaceship's engine

Summary

6. Sound FX and Music

SoundManager

Sound FX

How to create sound FXs

GameEvents

Using SoundPool

Playing music

Obtaining music

MediaPlayer

Music and Activity life cycle

Enabling and disabling music and sound FX

Updating MainMenuFragment

Updating SoundManager

Disabling system sounds

Summary

7. Menus and Dialogs

Custom fonts

Working with backgrounds

The power of XML drawables

State list drawables

State lists colors

Shape drawables

The GameFragment

Adding a score

Adding lives

Custom dialogs

BaseCustomDialog

Quit dialog

Pause dialog

Game Over dialog

Other dialogs

Designing for multiple screen sizes

Summary

8. The Animation Framework

Updating BaseFragment

AnimationDrawable

Animated sprites

Animating views

XML versus code

Interpolators

View animation

Animating dialogs

Delaying the action in the dialogs to onDismissed

Pulsating buttons

Property animation

ViewPropertyAnimator

Moving a spaceship around

Animating the main menu

Summary

9. Integrating Google Play Services

Setting up the developer console

Setting up the code

Achievements

Architecture

Unlocking achievements

Leaderboards

Opening the Play Games UI

Other features of Google Play services

Events

Quests

Gifts

Saved games

Multiplayer games

Summary

10. To the Big Screen

Project configuration

Testing for Android TV

Declaring a TV Activity

Providing a home screen banner

Declaring it as a game

Declaring Leanback support

Declaring touchscreen capability as not required

Reviewing the manifest

Showing controller instructions

Dealing with overscan

Controller-based navigation

Dialogs and controllers

Beyond this book

Summary

A. API Levels for Android Versions

A. Bibliography

Index

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部