ebook img

Beginning Android Games Development: From Beginner to Pro PDF

374 Pages·2020·11.884 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Beginning Android Games Development: From Beginner to Pro

Beginning Android Games Development From Beginner to Pro — Fourth Edition — Ted Hagos Mario Zechner J.F. DiMarzio Robert Green Beginning Android Games Development From Beginner to Pro Fourth Edition Ted Hagos Mario Zechner J.F. DiMarzio Robert Green Beginning Android Games Development: From Beginner to Pro Ted Hagos Mario Zechner Makati, Philippines Graz, Steiermark, Austria J.F. DiMarzio Robert Green Kissimmee, FL, USA Portland, OR, USA ISBN-13 (pbk): 978-1-4842-6120-0 ISBN-13 (electronic): 978-1-4842-6121-7 https://doi.org/10.1007/978-1-4842-6121-7 Copyright © 2020 by Ted Hagos, Mario Zechner, J.F. DiMarzio and Robert Green This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Spandana Chatterjee Development Editor: Laura Berendson Coordinating Editor: Divya Modi Cover designed by eStudi Pixabay Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected]; for reprint, paperback, or audio rights, please e-mail [email protected]. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/ 978-1-4842-6120-0. For more detailed information, please visit http://www.apress.com/ source-code. Printed on acid-free paper For Adrianne and Stephanie. Table of Contents About the Authors ��������������������������������������������������������������������������������xi About the Technical Reviewer �����������������������������������������������������������xiii Introduction ����������������������������������������������������������������������������������������xv Chapter 1: Setup �����������������������������������������������������������������������������������1 Installing Android Studio ���������������������������������������������������������������������������������������2 Configure Android Studio ��������������������������������������������������������������������������������������6 Hardware Acceleration ������������������������������������������������������������������������������������������9 Key Takeaways ����������������������������������������������������������������������������������������������������11 Chapter 2: Project Basics �������������������������������������������������������������������13 Create a Project ��������������������������������������������������������������������������������������������������13 Create an AVD �����������������������������������������������������������������������������������������������������18 Key Takeaways ����������������������������������������������������������������������������������������������������27 Chapter 3: Android Studio ������������������������������������������������������������������29 The IDE ����������������������������������������������������������������������������������������������������������������29 Main Editor ����������������������������������������������������������������������������������������������������������32 Editing Layout Files ���������������������������������������������������������������������������������������������33 Inserting TODO Items ������������������������������������������������������������������������������������������36 How to get more Screen Space for Code ������������������������������������������������������������37 Preferences/Settings ������������������������������������������������������������������������������������������42 Key Takeaways ����������������������������������������������������������������������������������������������������44 v Table of ConTenTs Chapter 4: What’s in an Android Application ��������������������������������������45 What makes up an Android Project ���������������������������������������������������������������������46 Application Entry Point ����������������������������������������������������������������������������������������49 Activities �������������������������������������������������������������������������������������������������������������50 Intents �����������������������������������������������������������������������������������������������������������������52 Key Takeaways ����������������������������������������������������������������������������������������������������54 Chapter 5: Introduction to Game Development �����������������������������������55 A Quick Tour of Game Genres ������������������������������������������������������������������������������56 Casual Games ������������������������������������������������������������������������������������������������56 Puzzle Games ������������������������������������������������������������������������������������������������58 Action Games ������������������������������������������������������������������������������������������������61 Tower Defense Games �����������������������������������������������������������������������������������62 Game Engine �������������������������������������������������������������������������������������������������������63 Key Takeaways ����������������������������������������������������������������������������������������������������65 Chapter 6: Building the Crazy Eights Game ����������������������������������������67 Basic Gameplay ��������������������������������������������������������������������������������������������������68 Key Parts of the Program ������������������������������������������������������������������������������������69 Custom Views and Activities �������������������������������������������������������������������������������70 Drawing on the Screen ���������������������������������������������������������������������������������������72 Handling Events ��������������������������������������������������������������������������������������������������74 SplashScreen with a Title Graphic ����������������������������������������������������������������������77 Adding the Play Button ����������������������������������������������������������������������������������������85 Launching the Game Screen �������������������������������������������������������������������������������90 Starting the Game �����������������������������������������������������������������������������������������������95 Displaying the Cards �����������������������������������������������������������������������������������������102 Handling Turns ��������������������������������������������������������������������������������������������������107 vi Table of ConTenTs Playing a Card ���������������������������������������������������������������������������������������������������107 When there is no Valid Play �������������������������������������������������������������������������������130 When it’s the Computer’s Turn ��������������������������������������������������������������������������133 Ending a Hand ���������������������������������������������������������������������������������������������������136 Chapter 7: Building the Balloon Popper Game ����������������������������������149 Game Mechanics�����������������������������������������������������������������������������������������������150 Creating the Project ������������������������������������������������������������������������������������������151 Drawing the Background ����������������������������������������������������������������������������������152 Game Controls and Pin Icons ����������������������������������������������������������������������������165 Drawing the Balloons ����������������������������������������������������������������������������������������181 Making the Balloons Float���������������������������������������������������������������������������������187 Launching the Balloons �������������������������������������������������������������������������������������194 Handling Game Levels ��������������������������������������������������������������������������������������198 Pop the Balloons �����������������������������������������������������������������������������������������������202 Managing the Pins ��������������������������������������������������������������������������������������������207 When the Game is Over �������������������������������������������������������������������������������������209 Audio �����������������������������������������������������������������������������������������������������������������214 Final Touches ����������������������������������������������������������������������������������������������������223 Chapter 8: Testing and Debugging ����������������������������������������������������235 Types of Game Testing ��������������������������������������������������������������������������������������235 Unit Testing �������������������������������������������������������������������������������������������������������238 JVM Test vs� Instrumented Test �������������������������������������������������������������������239 A Simple Demo ��������������������������������������������������������������������������������������������240 Implementing the Test ���������������������������������������������������������������������������������244 Running a Unit Test ��������������������������������������������������������������������������������������247 vii Table of ConTenTs Debugging ���������������������������������������������������������������������������������������������������������249 Syntax Errors �����������������������������������������������������������������������������������������������250 Runtime Errors ��������������������������������������������������������������������������������������������251 Logic Errors �������������������������������������������������������������������������������������������������252 Walking through the Code ���������������������������������������������������������������������������254 Profiler ��������������������������������������������������������������������������������������������������������������256 CPU ��������������������������������������������������������������������������������������������������������������258 Memory �������������������������������������������������������������������������������������������������������262 Network �������������������������������������������������������������������������������������������������������266 Energy ���������������������������������������������������������������������������������������������������������267 Key Takeaways ��������������������������������������������������������������������������������������������������268 Chapter 9: Introduction to OpenGL ES ����������������������������������������������269 What’s OpenGL ES ���������������������������������������������������������������������������������������������270 What does OpenGL ES do ����������������������������������������������������������������������������������272 Models or Objects ����������������������������������������������������������������������������������������274 Lights �����������������������������������������������������������������������������������������������������������275 Camera ��������������������������������������������������������������������������������������������������������275 Viewport ������������������������������������������������������������������������������������������������������275 Projections ��������������������������������������������������������������������������������������������������������276 Matrices ������������������������������������������������������������������������������������������������������������276 Rendering a Simple Sphere ������������������������������������������������������������������������������278 Key Takeaways ��������������������������������������������������������������������������������������������������315 Chapter 10: Monetization �����������������������������������������������������������������317 Paid or Free �������������������������������������������������������������������������������������������������������317 Freemium ����������������������������������������������������������������������������������������������������������319 In-app Purchase ������������������������������������������������������������������������������������������320 Virtual Currency �������������������������������������������������������������������������������������������321 viii Table of ConTenTs Advertising ��������������������������������������������������������������������������������������������������������321 Getting your Game Discovered ��������������������������������������������������������������������������322 Social Network ��������������������������������������������������������������������������������������������322 Discovery Services ��������������������������������������������������������������������������������������323 Blogs and Web Media ����������������������������������������������������������������������������������324 Game Design �����������������������������������������������������������������������������������������������������324 Key Takeaways ��������������������������������������������������������������������������������������������������326 Chapter 11: Publishing the Game �����������������������������������������������������327 Prepare the Project for Release ������������������������������������������������������������������������327 Prepare Material and Assets for Release ����������������������������������������������������328 Configure the App for Release ���������������������������������������������������������������������328 Build a Release-Ready Application ��������������������������������������������������������������329 Releasing the App ���������������������������������������������������������������������������������������������335 Key Takeaways ��������������������������������������������������������������������������������������������������339 Chapter 12: What’s Next �������������������������������������������������������������������341 Android NDK ������������������������������������������������������������������������������������������������������341 Vulkan ���������������������������������������������������������������������������������������������������������������346 Game Engines and Frameworks �����������������������������������������������������������������������352 Frameworks�������������������������������������������������������������������������������������������������353 Engines ��������������������������������������������������������������������������������������������������������354 Key Takeaways ��������������������������������������������������������������������������������������������������355 Index �������������������������������������������������������������������������������������������������357 ix About the Authors Ted Hagos is a software developer by trade. At the moment, he’s Chief Technology Officer and Data Protection Officer of RenditionDigital International, a software development company based out of Dublin. He wore many hats in his 20+ years in software development, for example, team lead, project manager, architect, and director for development. He also spent time as a trainer for IBM Advanced Career Education, Ateneo ITI, and Asia Pacific College. Mario Zechner runs Badlogic Games, a game development shop focused on Android.  J.F. DiMarzio is a seasoned Android developer and author. He began developing games in Basic on the TRS-80 Color Computer II in 1984. Since then, he has worked in the technology departments of companies such as the US Department of Defense and The Walt Disney Company. He has been developing on the Android platform since the beta release of version .03, and he has published two professional applications and one game on the Android marketplace. He is also an accomplished author. Over the last 10 years, he has released eight books, including Android: A Programmer's Guide. His books have been translated into four languages and published worldwide. His writing style is very easy to read and understand, which makes the information on the topics that he presents more retainable. xi

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.