封面
Learning Java by Building Android Games Second Edition
Why subscribe?
PacktPub.com
Contributors
About the author
About the reviewer
Packt is Searching for Authors Like You
Preface
About the book
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Chapter 1. Java Android and Game Development
What's new in the second edition?
Why Java Android and Games?
Java: The first stumbling block
The games you will build
Sub' Hunter
Pong
Bullet Hell
Snake Clone
Scrolling Shooter
Open-World Platformer
How Java and Android work
Setting up Android Studio
Final step
Starting the first project: Sub' Hunter
Extra step 1
Extra step 2
Android Studio and our project – A very brief guided tour
Locking the game to full-screen and landscape orientation
Deploying the game so far
Running the game on an Android emulator
Running the game on a real device
Summary
Chapter 2. Java: First Contact
Planning the Sub' Hunter game
Actions flowchart/diagram
Mapping out our code using comments
Introduction to Java methods
Overriding methods
Structuring Sub' Hunter with methods
Introduction to Object Oriented Programming
Classes and Objects
Final word on OOP Classes and Objects – for now
Using Java packages
Adding classes by importing packages
Linking up our methods
Summary
Chapter 3. Variables Operators and Expressions
Handling syntax and jargon
Java Variables
Different types of variables
How to use variables
Declaring variables
Initializing variables
Making variables useful with operators
Most used operators in this book
Declaring and Initializing the Sub' Hunter Variables
Planning the variables
Declaring the variables
Handling different screen sizes and resolutions
Handling different screen resolutions part 1: Initialising the variables
Errors warnings and bugs
Printing Debugging Information
Testing the game
Summary
Chapter 4. Structuring Code with Java Methods
Methods
Methods revisited and explained further
Method Overloading by Example
Scope: Methods and Variables
Revisiting the code and methods we have used already
Generating random numbers to deploy a sub
The Random class and the nextInt method
Testing the game
Summary
Chapter 5. The Android Canvas Class – Drawing to the Screen
Understanding the Canvas class
Getting started drawing with Bitmap Canvas and ImageView
Using the Canvas class
Preparing the objects of classes
Initializing the objects
Setting the Activity content
Canvas Demo app
Creating a new project
Android Coordinate system
Plotting and drawing
Drawing the Sub' Hunter graphics and text
Preparing to draw
Initializing a Canvas Paint ImageView and Bitmap
Drawing some grid lines
Drawing the HUD
Upgrading the printDebuggingText method
Summary
Chapter 6. Repeating Blocks of Code with Loops
Decisions decisions
Keeping things tidy
More operators
Loops
While loops
Do while loops
For loops
Using for loops to draw the Sub' Hunter grid
Summary
Chapter 7. Making Decisions with Java If Else and Switch
If they come over the bridge shoot them
Else do this instead
Switching to make decisions
Combining different control flow blocks
Making sense of the screen touches
Coding the onTouchEvent method
Final tasks
Coding the takeShot method
Explaining the takeShot method
Coding the boom method
Drawing the shot on the grid
Running the game
Summary
Chapter 8. Object-Oriented Programming
Basic Object-Oriented Programming
Humans learn by doing
Introducing OOP
Why we do it like this?
Class recap
Looking at the code for a class
Class implementation
Declaring initializing and using an object of the class
Basic classes mini-app
Creating your first class
More things we can do with our first class
Remember that encapsulation thing?
Controlling class use with access modifiers
Controlling variable use with access modifiers
Methods have access modifiers too
Accessing private variables with getters and setters
Setting up our objects with constructors
Using "this"
Static methods
Encapsulation and static methods mini-app
OOP and inheritance
Inheritance mini-app
Polymorphism
Abstract classes
Interfaces
Starting the Pong game
Planning the Pong game
Setting up the Pong project
Summary
Chapter 9. The Game Engine Threads and The Game Loop
Coding the PongActivity class
Coding the PongGame class
Coding the PongGame class
Adding the member variables
Coding the PongGame constructor
Coding the startNewGame method
Coding the draw method
Understanding the draw method and the SurfaceView class
The game loop
Threads
Problems with threads
Java try catch exception handling
Implementing the game loop with a thread
Implementing Runnable and providing the run method
Coding the thread
Starting and stopping the thread
Activity lifecycle
A simplified explanation of the Android lifecycle
Lifecycle phases: What we need to know
Lifecycle phases: What we need to do
Using the Activity lifecycle to start and stop the thread
Coding the run method
Running the game
Summary
Chapter 10. Coding the Bat and Ball
The Ball Class
Communicating with the game engine
Representing rectangles and squares with RectF
Coding the variables
Coding the Ball constructor
Coding the RectF getter method
Coding the Ball update method
Coding the Ball helper methods
Coding a realistic-ish bounce
Using the Ball class
The Bat class
Coding the Bat variables
Coding the Bat constructor
Coding the Bat helper methods
Coding the Bat's update method
Using the Bat Class
Coding the Bat input handling
Running the game
Summary
Chapter 11. Collisions Sound Effects and Supporting Different Versions of Android
Handling collisions
Collision detection options
Optimizations
Best options for Pong
The RectF intersects method
Handling different versions of Android
Detecting the current Android version
The Soundpool class
Initializing SoundPool the new way
Generating sound effects
Adding sound to the Pong game
Adding the sound variables
Initializing the SoundPool
Coding the collision detection and playing sounds
The bat and the ball
The four walls
Playing the game
Summary
Chapter 12. Handling Lots of Data with Arrays
Planning the project
Starting the project
Change the AndroidManifest.xml to lock in landscape and full-screen
Creating the classes
Reusing the Pong engine
Coding the BulletHellActivity
Coding the BulletHellGame class
Testing the Bullet Hell engine
Coding the Bullet class
Java Arrays
Arrays are objects
Simple array example mini-app
Getting dynamic with arrays
Dynamic array example
Entering the nth dimension with Arrays
Multidimensional Array mini app
Array out of bounds exceptions
Spawning an array of bullets
Running the game
Summary
Chapter 13. Bitmap Graphics and Measuring Time
The Bob (player's) class
Adding the Bob graphic to the project
Coding the Bob class
Using the Bob class
Running the game
Summary
Chapter 14. The Stack the Heap and the Garbage Collector
Managing and understanding memory
Variables revisited
Introduction to the Snake game
Looking ahead to the Snake game
Getting started with the Snake game
Make full screen and landscape
Adding some empty classes
Coding SnakeActivity
Adding the sound effects
Coding the game engine
Coding the members
Coding the constructor
Coding the newGame method
Coding the run method
Coding the updateRequired method
Coding the update method
Coding the draw method
Coding onTouchEvent
Coding pause and resume
Running the game
Summary
Chapter 15. Android Localization -Hola!
Making the snake game Spanish English and German
Adding Spanish support
Adding German support
Add the string resources
Amending the code
Run the game in German or Spanish
Summary
Chapter 16. Collections Generics and Enumerations
Adding the graphics
Coding the apple
The Apple constructor
Using the apple
Running the game
Using Arrays in the snake game
ArrayLists
The enhanced for loop
Arrays and ArrayLists are polymorphic
Enumerations
Summary
Chapter 17. Manipulating Bitmaps and Coding the Snake class
Rotating Bitmaps
What is a Bitmap exactly
The Matrix class
Add the sound to the project
Coding the Snake class
Coding the constructor
Coding the reset method
Coding the move method
Coding the detectDeath method
Coding the checkDinner method
Coding the draw method
Coding the switchHeading method
Using the snake class and finishing the game
Running the completed game
Summary
Chapter 18. Introduction to Design Patterns and much more!
Introducing the Scrolling Shooter project
Game programming patterns and the structure of the Scrolling Shooter project
Starting the project
Editing the manifest
Code the GameActivity class
Getting started on the GameEngine class
Controlling the game with a GameState class
Passing GameState from GameEngine to other classes
Communicating from GameState to GameEngine
Giving partial access to a class using an interface
Interface refresher
What we will do to implement the interface solution
Coding the GameState class
Saving and loading the high score- forever
4. Pressing the "special button" - Calling the method of the interface
Finishing off the GameState class
Using the GameState class
Building a sound engine
Adding the sound files to the project
Coding the SoundEngine class
Using the SoundEngine class
Testing the game so far
Building a HUD class to display control buttons and text
Coding the prepareControls method
Coding the draw method of the HUD class
Coding drawControls and getControls
Building a Renderer class to handle the drawing
Using the HUD and Renderer classes
Running the game
Summary
Chapter 19. Listening with the Observer Pattern Multitouch and Building a Particle System
The Observer pattern
The Observer pattern in the Scrolling Shooter project
Coding the Observer pattern in Scrolling Shooter
Coding the Broadcaster interface
Coding the InputObserver interface
Making GameEngine a Broadcaster
Coding a Multitouch UI controller and making it a listener
Coding the required handleInput method
Using the UIController
Running the game
Implementing a particle system explosion
Coding the Particle class
Coding the ParticleSystem class
Adding a particle system to the game engine and drawing it with the Renderer
Building a physics engine to get things moving
Running the game
Summary
Chapter 20. More Patterns a Scrolling Background and Building the Player's ship
Meet the game objects
Reminder of how all these objects will behave
The Entity-Component pattern
Why lots of diverse object types are hard to manage
The first coding nightmare
Using a generic GameObject for better code structure
Composition over inheritance
The Simple Factory pattern
At last some good news
Summary so far
The object specifications
Coding the ObjectSpec parent class
Coding all the specific object specifications
Coding the component Interfaces
GraphicsComponent
InputComponent
MovementComponent
SpawnComponent
Coding the player's and the background's empty component classes
StdGraphicsComponent
PlayerMovementComponent
PlayerSpawnComponent
PlayerInputComponent and the PlayerLaserSpawner interface
LaserMovementComponent
LaserSpawnComponent
BackgroundGraphicsComponent
BackgroundMovementComponent
BackgroundSpawnComponent
Every GameObject has a transform
Every object is a GameObject
Completing the player's and the background's components
The player's components
Coding a scrolling background
GameObject/Component reality check
Building the GameObjectFactory
Coding the Level class
Putting everything together
Updating GameEngine
Updating PhysicsEngine
Updating Renderer
Running the game
Summary
Chapter 21. Completing the Scrolling Shooter Game
Adding the alien's components
AlienChaseMovementComponent
AlienDiverMovementComponent
AlienHorizontalSpawnComponent
AlienPatrolMovementComponent
AlienVerticalSpawnComponent
Spawning the Aliens
Updating GameEngine
Updating Level
Updating GameObjectFactory
Running the game
Detecting collisions
Running the completed game
Summary
Chapter 22. Exploring More Patterns and Planning the Platformer Project
Platform Game: Bob Was in A Hurry
How we will build the platformer
Level design files example
The graphics
Cameras and the real world
The slightly modified ObjectSpec
New improved transform hierarchy
Project patterns
Getting started with Bob was in a hurry
Creating the project and adding the assets
Specifying all the game objects with GameObjectSpec classes
GameObjectSpec
BackgroundCitySpec
BackgroundMountainSpec
BackgroundUndergroundSpec
BrickTileSpec
CartTileSpec
CoalTileSpec
CollectibleObjectSpec
ConcreteTileSpec
DeadTreeTileSpec
FireTileSpec
GrassTileSpec
LamppostTileSpec
MoveablePlatformSpec
ObjectiveTileSpec
PlayerSpec
ScorchedTileSpec
SnowTileSpec
SnowyTreeTileSpec
StalactiteTileSpec
StalagmiteTileSpec
StonePileTileSpec
Summary of component classes
Coding the component interfaces
GraphicsComponent
UpdateComponent
Coding the other interfaces
EngineController
GameEngineBroadcaster
InputObserver
Summary
Chapter 23. The Singleton Pattern Java HashMap Storing Bitmaps Efficiently and Designing Levels
The Singleton pattern
The Singleton code
More Java Collections – Meet Java Hashmap
The memory problem and the BitmapStore
Coding the BitmapStore class
Coding the basic transform
Coding the inanimate and decorative components
DecorativeBlockUpdateComponent
InanmiateBlockGraphicsComponent
InanimateBlockUpdateComponent
Create the levels
Level
LevelCity
LevelMountains
LevelUnderground
Coding a stripped down GameObjectFactory
Coding a slightly commented-out game object
Coding the GameState
Code the SoundEngine
Coding the physics engine (without collision)
Coding a Renderer
Coding the camera
Testing the formulas with hypothetical coordinates
Coding the Hud
Coding the UIController class
Code the Activity
Code the GameEngine
Coding the LevelManager class
Running the game
Summary
Chapter 24. Sprite-sheet animations Controllable Player and Parallax Scrolling Backgrounds
Animating sprite-sheets
Coding the Animator
Coding the player's components and transform
PlayerTransform
AnimatedGraphicsComponent
PlayerInputComponent
PlayerUpdateComponent
Coding a parallax background
Coding the BackgroundTransform
Coding the BackgroundGraphicsComponent
Coding the BackgroundUpdateComponent
Updating the levelManager GameObjectFactory and GameObject
Running the game
Summary
Chapter 25. Intelligent Platforms and Advanced Collision Detection
Coding the moving platform component class
MoveableBlockUpdateComponent
Update LevelManager and GameObjectFactory
Running the game
Coding the detectCollisions method: Part 1
Explaining part 1
Coding the detectCollisions method: Part 2
Explaining part 2
Running the game
Summary
Chapter 26. What next?
Publishing
Using the assets from the book
Future learning
My other channels
Thanks
更新时间:2021-07-23 19:03:48