Learning Java by Building Android Games Second Edition
Copyright 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Amarabha Banerjee
Acquisition Editor: Reshma Raman
Content Development Editors: Onkar Wani
Technical Editor: Ralph Rosario
Copy Editor: SAFIS
Project Coordinator: Devanshi Doshi
Proofreader: Safis Editing
Indexers: Pratik Shirodkar
Graphics: Jason Monterio
Production Coordinator: Aparna Bhagat
First published: January 2015
Second edition: August 2018
Production reference: 1270818
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78883-915-0
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
- Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
- Learn better with Skill Plans built especially for you
- Get a free eBook or video every month
- Mapt is fully searchable
- Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com
for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
About the reviewer
Boon Hian Tek is a 18 years Java veteran. He has honed his software development skills in a varying industries. He helped bringing medical records online, aided the advertising industry target ads, assisted in getting disposing of chemical weapons, and more recently part of making fin tech work some wonders.
He is always passionate with automation. Boon spends his days automating so that he can spend more time with his family. No one should spend be forced to spend time doing mundane stuff. Except for wax on, wax off!
He works for one of the largest fin tech in Singapore also reviewed First Edition of this book.
My wife and daughter putting up with the time I spent away from them to help with the book.
Packt is Searching for Authors Like You
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Preface
About the book
Android is one of the most popular mobile operating systems presently. It uses the most popular programming language, Java, as the primary language for building apps of all types. However, this book is unlike other Android books in that it doesn't assume that you already have Java proficiency.
This new and expanded second edition of Learning Java by Building Android Games shows you how to start building Android games from scratch. The difficulty level will grow steadily as you explore key Java topics, such as variables, loops, methods, object-oriented programming, and design patterns, including code and examples that are written for Java 9 and Android P.
At each stage, you will put what you've learned into practice by developing a game. You will build games such as Minesweeper, Retro Pong, Bullet Hell, and Classic Snake and Scrolling Shooter games. In the later chapters, you will create a time-trial, open-world platform game.
By the end of the book, you will not only have grasped Java and Android but will also have developed six cool games for the Android platform.
Who this book is for
Learning Java by Building Android Games is for you if you are completely new to Java, Android, or game programming, and you want to make Android games. This book also acts as a refresher for those who already have experience of using Java on Android or any other platform without game development experience.
What this book covers
, Java, Android, and Game Development , In this first chapter we will get straight into Java, Android and game development. Also, we will look at some images and an outline of each of the six games we will develop throughout the book. Further, we will explore and discover what is so great about Android, what exactly Android and Java are, how they work and complement each other. Moving quickly on we will set up the required software and then build and deploy the outline for the first game.
, Java: First Contact , In this chapter, we will make significant progress with the Sub' Hunter game even though this is the first lesson on Java. We will look in detail at exactly how Sub' Hunter will be played and the steps/flow that our completed code will need to take to implement it. We will also learn about Java code comments for documenting the code, take a brief initial glimpse at methods to structure our code and an even briefer first glimpse at object-oriented programming that will begin to reveal the power of Java and the Android API.
, Variables, Operators, and Expressions , We are going to make good progress in this chapter. We will learn about Java variables that allows us to give our game the data it needs. Things like the sub's location and whether it has been hit, will soon be possible to code. Furthermore, the use of operators and expressions