Game Development with LibGDX

From Beginner to Professional

Second Edition

Lee Stemkoski Java Game Development with LibGDX: From Beginner to Professional Lee Stemkoski Garden City, New York, USA ISBN-13 (pbk): 978-1-4842-3323-8 ISBN-13 (electronic): 978-1-4842-3324-5 https://doi.org/10.1007/978-1-4842-3324-5 Library of Congress Control Number: 2018931188 Copyright © 2018 by Lee Stemkoski 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. Cover image by Freepik (www.freepik.com) Managing Director: Welmoed Spahr Editorial Director: Todd Green Acquisitions Editor: Steve Anglin Development Editor: Matthew Moodie Technical Reviewer: Garry Patchett Coordinating Editor: Mark Powers Copy Editor: April Rondeau 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, email [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 email [email protected], or visit http://www.apress.com/ rights-permissions. 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 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/9781484233238. For more detailed information, please visit http://www.apress.com/source-code. Printed on acid-free paper Contents

About the Author ����������������������������������������������������������������������������������������������������� xi About the Technical Reviewer ������������������������������������������������������������������������������� xiii Acknowledgments ���������������������������������������������������������������������������������������������������xv Introduction �����������������������������������������������������������������������������������������������������������xvii

■■Part I: Fundamental Concepts ������������������������������������������������������������ 1 ■■Chapter 1: Getting Started with Java and LibGDX ������������������������������������������������� 3 Choosing a Development Environment ���������������������������������������������������������������������������� 3 Setting Up BlueJ ��������������������������������������������������������������������������������������������������������������� 4 Downloading and Installing ��������������������������������������������������������������������������������������������������������������������4 Using BlueJ ���������������������������������������������������������������������������������������������������������������������������������������������5 Setting Up LibGDX ����������������������������������������������������������������������������������������������������������������������������������8 Creating a “Hello, World!” Program with LibGDX �������������������������������������������������������������� 9 Advantages to Using LibGDX ������������������������������������������������������������������������������������������ 14 Summary ������������������������������������������������������������������������������������������������������������������������ 14 ■■Chapter 2: The LibGDX Framework ���������������������������������������������������������������������� 15 The Life Cycle of a Video Game �������������������������������������������������������������������������������������� 16 Game Project: Starfish Collector ������������������������������������������������������������������������������������ 19 Managing Game Entities with Actors and Stages ���������������������������������������������������������� 24 Reorganizing the Game Flow ����������������������������������������������������������������������������������������� 32 Summary and Next Steps ����������������������������������������������������������������������������������������������� 37

iii ■ CONTENTS

■■Chapter 3: Extending the Framework ������������������������������������������������������������������ 39 Animation ����������������������������������������������������������������������������������������������������������������������� 41 Value-Based Animations �����������������������������������������������������������������������������������������������������������������������41 Image-Based Animations ����������������������������������������������������������������������������������������������������������������������42 Physics and Movement �������������������������������������������������������������������������������������������������� 54 Velocity �������������������������������������������������������������������������������������������������������������������������������������������������54 Acceleration ������������������������������������������������������������������������������������������������������������������������������������������56 Movement ���������������������������������������������������������������������������������������������������������������������������������������������58 Collision Polygons ���������������������������������������������������������������������������������������������������������� 60 Polygons Versus Rectangles �����������������������������������������������������������������������������������������������������������������60 Detecting Collisions ������������������������������������������������������������������������������������������������������������������������������63 Simulating Solid Objects ����������������������������������������������������������������������������������������������������������������������65 Managing Collections of Actors �������������������������������������������������������������������������������������� 67 World Boundaries ����������������������������������������������������������������������������������������������������������� 72 Multiple Screens ������������������������������������������������������������������������������������������������������������ 76 Summary and Next Steps ����������������������������������������������������������������������������������������������� 81 ■■Chapter 4: Shoot-em-up games �������������������������������������������������������������������������� 83 Game Project: Space Rocks ������������������������������������������������������������������������������������������� 83 Discrete Input ����������������������������������������������������������������������������������������������������������������� 84 Spaceship Setup ������������������������������������������������������������������������������������������������������������ 87 Lasers, Rocks, and Explosions ��������������������������������������������������������������������������������������� 94 Endgame Conditions ������������������������������������������������������������������������������������������������������ 97 Summary and Next Steps ����������������������������������������������������������������������������������������������� 98 ■■Chapter 5: Text and User Interfaces �������������������������������������������������������������������� 99 Displaying Text ������������������������������������������������������������������������������������������������������������� 101 Bitmap Fonts ��������������������������������������������������������������������������������������������������������������������������������������101 Labels �������������������������������������������������������������������������������������������������������������������������������������������������104

iv ■ CONTENTS

Buttons ������������������������������������������������������������������������������������������������������������������������� 106 Image-Based Buttons �������������������������������������������������������������������������������������������������������������������������108 Text-Based Buttons ����������������������������������������������������������������������������������������������������������������������������110 Organizing Layouts with Tables ������������������������������������������������������������������������������������ 114 Signs and Dialog Boxes ������������������������������������������������������������������������������������������������ 116 Creating Cutscenes ������������������������������������������������������������������������������������������������������ 121 Game Project: Visual Novels ����������������������������������������������������������������������������������������� 129 Summary and Next Steps ��������������������������������������������������������������������������������������������� 141 ■■Chapter 6: Audio ������������������������������������������������������������������������������������������������ 143 Sounds and Music �������������������������������������������������������������������������������������������������������� 143 Game Project: Rhythm Tapper �������������������������������������������������������������������������������������� 147 Working with Files �������������������������������������������������������������������������������������������������������� 148 Browsing for Files �������������������������������������������������������������������������������������������������������������������������������148 Recording Song Data ��������������������������������������������������������������������������������������������������������������������������151 The Game Application �������������������������������������������������������������������������������������������������� 157 Synchronizing Game Objects and Audio ���������������������������������������������������������������������������������������������160 Adding Interactivity and Creating the User Interface ��������������������������������������������������������������������������162 Finishing Touches �������������������������������������������������������������������������������������������������������������������������������166 Summary and Next Steps ��������������������������������������������������������������������������������������������� 169

■■Part II: Intermediate Examples ������������������������������������������������������� 171 ■■Chapter 7: Side-Scrolling Games ����������������������������������������������������������������������� 173 Game Project: Plane Dodger ����������������������������������������������������������������������������������������� 173 Infinite Scrolling ����������������������������������������������������������������������������������������������������������� 175 The Player Plane and Simulating Gravity ��������������������������������������������������������������������� 178 Collectibles and Obstacles ������������������������������������������������������������������������������������������� 180 Stars ���������������������������������������������������������������������������������������������������������������������������������������������������180 The Enemy Planes ������������������������������������������������������������������������������������������������������������������������������182 Finishing Touches ��������������������������������������������������������������������������������������������������������� 185 Summary and Next Steps ��������������������������������������������������������������������������������������������� 187

v ■ CONTENTS

■■Chapter 8: Bouncing and Collision Games ��������������������������������������������������������� 189 Game Project: Rectangle Destroyer ������������������������������������������������������������������������������ 189 Creating the Game Objects ������������������������������������������������������������������������������������������� 190 Paddle �������������������������������������������������������������������������������������������������������������������������������������������������191 Walls ���������������������������������������������������������������������������������������������������������������������������������������������������192 Bricks �������������������������������������������������������������������������������������������������������������������������������������������������193 Ball �����������������������������������������������������������������������������������������������������������������������������������������������������194 Bouncing Around ���������������������������������������������������������������������������������������������������������� 196 User Interface ��������������������������������������������������������������������������������������������������������������� 197 Items ���������������������������������������������������������������������������������������������������������������������������� 199 Sounds and Music �������������������������������������������������������������������������������������������������������� 203 Summary and Next Steps ��������������������������������������������������������������������������������������������� 205 ■■Chapter 9: Drag-and-Drop Games ��������������������������������������������������������������������� 207 Drag-and-Drop Functionality ���������������������������������������������������������������������������������������� 209 Game Project: Jigsaw Puzzle ��������������������������������������������������������������������������������������� 214 Game Project: 52 Card Pickup �������������������������������������������������������������������������������������� 219 Summary and Next Steps ��������������������������������������������������������������������������������������������� 225 ■■Chapter 10: Tilemaps ����������������������������������������������������������������������������������������� 227 Revisiting the Starfish Collector Game ������������������������������������������������������������������������� 228 Creating the Tilemap ���������������������������������������������������������������������������������������������������������������������������229 Creating the TilemapActor Class ���������������������������������������������������������������������������������������������������������236 Project Integration ������������������������������������������������������������������������������������������������������������������������������240 Rectangle Destroyer Revisited ������������������������������������������������������������������������������������� 241 Creating the Tilemap ���������������������������������������������������������������������������������������������������������������������������241 Project Integration ������������������������������������������������������������������������������������������������������������������������������244 Summary and Next Steps ��������������������������������������������������������������������������������������������� 246 ■■Chapter 11: Platform Games ����������������������������������������������������������������������������� 247 Game Project: Jumping Jack ���������������������������������������������������������������������������������������� 248 Starting the Level ��������������������������������������������������������������������������������������������������������� 249

vi ■ CONTENTS

Platform Character Setup ��������������������������������������������������������������������������������������������� 252 Game-World Objects ���������������������������������������������������������������������������������������������������� 258 User Interface �������������������������������������������������������������������������������������������������������������������������������������260 The Goal: Reach the Flag ��������������������������������������������������������������������������������������������������������������������261 Coins ���������������������������������������������������������������������������������������������������������������������������������������������������262 Time and Timers ���������������������������������������������������������������������������������������������������������������������������������262 Springboards ��������������������������������������������������������������������������������������������������������������������������������������264 Platforms ��������������������������������������������������������������������������������������������������������������������������������������������265 Keys and Locks �����������������������������������������������������������������������������������������������������������������������������������267 Summary and Next Steps ��������������������������������������������������������������������������������������������� 270 ■■Chapter 12: Adventure Games ��������������������������������������������������������������������������� 271 Game Project: Treasure Quest �������������������������������������������������������������������������������������� 272 Level Setup ������������������������������������������������������������������������������������������������������������������� 273 The Hero ����������������������������������������������������������������������������������������������������������������������� 276 The Sword �������������������������������������������������������������������������������������������������������������������� 280 Bushes and Rocks �������������������������������������������������������������������������������������������������������� 283 User Interface ��������������������������������������������������������������������������������������������������������������� 284 Enemies ������������������������������������������������������������������������������������������������������������������������ 288 Arrows �������������������������������������������������������������������������������������������������������������������������� 290 Non-Player Characters ������������������������������������������������������������������������������������������������� 292 Item Shop ��������������������������������������������������������������������������������������������������������������������� 295 Summary and Next Steps ��������������������������������������������������������������������������������������������� 296

■■Part III: Advanced Topics ���������������������������������������������������������������� 297 ■■Chapter 13: Alternative Sources of User Input �������������������������������������������������� 299 Gamepad Controllers ���������������������������������������������������������������������������������������������������� 299 Continuous Input ���������������������������������������������������������������������������������������������������������������������������������300 Discrete Input �������������������������������������������������������������������������������������������������������������������������������������303

vii ■ CONTENTS

Touchscreen Controls ��������������������������������������������������������������������������������������������������� 305 Redesigning the Window Layout ��������������������������������������������������������������������������������������������������������306 Working with a Touchpad �������������������������������������������������������������������������������������������������������������������308 Summary and Next Steps ��������������������������������������������������������������������������������������������� 310 ■■Chapter 14: Maze Games ����������������������������������������������������������������������������������� 311 Game Project: Maze Runman ��������������������������������������������������������������������������������������� 311 Maze Generation ���������������������������������������������������������������������������������������������������������� 312 The Hero ����������������������������������������������������������������������������������������������������������������������� 322 The Ghost ��������������������������������������������������������������������������������������������������������������������� 325 Winning and Losing the Game �������������������������������������������������������������������������������������� 329 Audio ���������������������������������������������������������������������������������������������������������������������������� 332 Summary and Next Steps ��������������������������������������������������������������������������������������������� 333 ■■Chapter 15: Advanced 2D Graphics ������������������������������������������������������������������� 335 Particle Systems ���������������������������������������������������������������������������������������������������������� 335 The LibGDX Particle Editor ������������������������������������������������������������������������������������������������������������������335 Rocket-Thruster Effect �����������������������������������������������������������������������������������������������������������������������338 Explosion Effect ����������������������������������������������������������������������������������������������������������������������������������339 The ParticleActor Class �����������������������������������������������������������������������������������������������������������������������340 Integrating Particle Effects into Gameplay �����������������������������������������������������������������������������������������342 Shader Programming ��������������������������������������������������������������������������������������������������� 345 Default Shaders ����������������������������������������������������������������������������������������������������������������������������������346 Using Shaders in LibGDX ��������������������������������������������������������������������������������������������������������������������348 Grayscale Shader ��������������������������������������������������������������������������������������������������������������������������������349 Custom Uniform Values ����������������������������������������������������������������������������������������������������������������������349 Border Shader ������������������������������������������������������������������������������������������������������������������������������������350 Blur Shader �����������������������������������������������������������������������������������������������������������������������������������������352 Glow Shader ���������������������������������������������������������������������������������������������������������������������������������������354 Wave-Distortion Shader ����������������������������������������������������������������������������������������������������������������������355 Summary and Next Steps ��������������������������������������������������������������������������������������������� 357

viii ■ CONTENTS

■■Chapter 16: Introduction to 3D Graphics and Games ���������������������������������������� 359 Exploring 3D Concepts and Classes ����������������������������������������������������������������������������� 359 Creating a Minimal 3D Demo ��������������������������������������������������������������������������������������� 362 Recreating the Actor/Stage Framework ����������������������������������������������������������������������� 365 The BaseActor3D Class ����������������������������������������������������������������������������������������������������������������������365 The Stage3D Class ������������������������������������������������������������������������������������������������������������������������������369 Creating an Interactive 3D Demo ��������������������������������������������������������������������������������������������������������373 Game Project: Starfish Collector 3D ����������������������������������������������������������������������������� 380 Summary and Next Steps ��������������������������������������������������������������������������������������������� 389 ■■Chapter 17: The Journey Continues ������������������������������������������������������������������ 391 Continuing Developing ������������������������������������������������������������������������������������������������� 391 Working on Projects ���������������������������������������������������������������������������������������������������������������������������391 Obtaining Art Resources ���������������������������������������������������������������������������������������������������������������������392 Participating in Game Jams ����������������������������������������������������������������������������������������������������������������393 Overcoming Difficulties ����������������������������������������������������������������������������������������������������������������������393 Broadening Your Horizons �������������������������������������������������������������������������������������������� 394 Playing Different Games ���������������������������������������������������������������������������������������������������������������������394 Increasing Your Skill Set ���������������������������������������������������������������������������������������������������������������������395 Recommended Reading ���������������������������������������������������������������������������������������������������������������������395 Disseminating Your Games ������������������������������������������������������������������������������������������� 396 Packaging for Desktop Computers �����������������������������������������������������������������������������������������������������396 Compiling for Other Platforms ������������������������������������������������������������������������������������������������������������397 Finding Distribution Outlets ����������������������������������������������������������������������������������������������������������������399 ■■Appendix A: Game Design Documentation �������������������������������������������������������� 401 Game Design Documentation Questions ���������������������������������������������������������������������� 402 Case Study: Space Rocks ��������������������������������������������������������������������������������������������� 405 ■■Appendix B: Review of Java Fundamentals ������������������������������������������������������� 411 Data Types and Operators �������������������������������������������������������������������������������������������� 411

ix ■ CONTENTS

Control Structures �������������������������������������������������������������������������������������������������������� 412 Conditional Statements ����������������������������������������������������������������������������������������������������������������������412 Repetition Statements ������������������������������������������������������������������������������������������������������������������������414 Methods ����������������������������������������������������������������������������������������������������������������������� 415 Objects and Classes ����������������������������������������������������������������������������������������������������� 416 Summary ���������������������������������������������������������������������������������������������������������������������� 418 ■■Appendix : Extended Framework Class Reference ������������������������������������������ 419 The BaseScreen Class �������������������������������������������������������������������������������������������������� 419 Constructor �����������������������������������������������������������������������������������������������������������������������������������������419 Fields ��������������������������������������������������������������������������������������������������������������������������������������������������419 Methods ����������������������������������������������������������������������������������������������������������������������������������������������420 The BaseActor Class ���������������������������������������������������������������������������������������������������� 421 Constructor �����������������������������������������������������������������������������������������������������������������������������������������421 Methods ����������������������������������������������������������������������������������������������������������������������������������������������421 The TilemapActor Class ������������������������������������������������������������������������������������������������ 423 Constructor �����������������������������������������������������������������������������������������������������������������������������������������423 Fields ��������������������������������������������������������������������������������������������������������������������������������������������������423 Methods ����������������������������������������������������������������������������������������������������������������������������������������������424

Index ��������������������������������������������������������������������������������������������������������������������� 425

x About the Author

Lee Stemkoski is a professor of computer science and mathematics. He earned his Ph.D. in mathematics from Dartmouth College in 2006. He has been teaching at the college level since, with an emphasis on Java programming, computer graphics, and video game development since 2010. Lee particularly enjoys playing classic games released for the Nintendo and Super Nintendo Entertainment System consoles. He has written another book, Game Development with 2, in addition to many other scholarly articles and game development tutorials.

xi About the Technical Reviewer

Garry Patchett has worked in IT and engineering for more than 20 years designing products, creating software, and administering and documenting systems. With a master’s degree in project management, he is a dedicated “systems nerd” whose interests vary from the technological to the philosophical. Garry is currently working freelance and is involved in various open source projects.

xiii Acknowledgments

I would like to acknowledge the amazing editorial and support staff at Apress, for without their talent and dedication this book you are reading would not exist. In particular, I’d like to thank Mark Powers for his constant words of support and encouragement. I’d also like to thank the technical reviewer, Garry Patchett, for his attention to both the programming and the pedagogical aspects of this book. From the very beginning, he intuitively understood who the target audience was and the level of detail and guidance they needed. Garry’s many insightful comments and suggestions greatly improved the clarity of this book, and I am grateful for all the time and energy he put into helping to make this book the best that it could be. Finally, a special thanks to my students, past and present, for their continuous and infectious enthusiasm. Your drive and devotion to game development is what inspired me to write this book.

xv Introduction

Welcome to Java Game Development with LibGDX! In this book, you’ll learn how to program games in Java using the LibGDX game development framework. The LibGDX libraries are both powerful and easy to use, and they will enable you to create a great variety of games quickly and efficiently. LibGDX is free and open source, can be used to make 2D and 3D games, and integrates easily with third-party libraries to support additional features. I have taught courses in Java programming and video game development for many years, and I’ve often struggled to find game-programming books that I can recommend to my students without reservation, which led me to write this book you are currently reading. In particular, you will find that this book contains the following unique combination of features, chosen with the aspiring game developer (that’s you!) in mind: • This book recommends and explains how to use a simple Java development environment so that you can move on to programming games more quickly. • By using the LibGDX framework, you won’t have to “reinvent the wheel” for common programming tasks such as rendering graphics and playing audio. (An explanation of how to write such code from scratch would easily require fifty or more additional pages of reading.) LibGDX streamlines the development process and allows you to focus on game mechanics and design. • This book contains many examples of video games that can be developed with LibGDX. The first part of the book will introduce you to the basic features provided by the framework. The second part will cover a variety of games to illustrate the power and flexibility of LibGDX. The third part of the book will introduce some advanced techniques to incorporate into previous and new game projects. I believe that working through many examples is fundamental to the learning process; you will observe programming patterns common to many games, see the benefits of writing reusable code in practice, have the opportunity to compare and contrast code from different projects, and gain experience by implementing additional features on your own. • At the beginning of this book, I am assuming that you have only a basic familiarity with Java programming. (For more details about what background knowledge you need, please consult the appendix.) Throughout the first few chapters of this book, advanced programming concepts will be introduced and explained as they arise naturally and are needed in the context of game programming. By the time you reach the end of this book, you will have learned about many advanced Java programming topics that are also useful for software development in general. Thank you for allowing me to be your guide as you begin your journey as a game . I hope that you will find this book both informative and enjoyable, and that it enables and inspires you to create your own video games to share with the world.

xvii ■ INTRODUCTION Video Game Projects As mentioned previously, this book is unique in the number and variety of games that are covered. In particular, you will learn how to create the following 12 video games in this book: • Starfish Collector. In this game, you guide a turtle who is on a quest to collect starfish. This simple game is used to introduce the functionality of LibGDX and the extended framework you will create, and is revisited frequently throughout the book when introducing new features, such as user interfaces, cutscenes, audio, tilemaps, and gamepad controls. • Space Rocks. This space-themed shoot-em-up game is inspired by the classic arcade game Asteroids, in which you control a spaceship and shoot lasers to destroy rocks that are flying around the screen. • The Missing Homework. This is a visual novel–style game that is completely story driven. It presents to the player a series of choices that influence the progression of the story. In this game, you help a student to locate his misplaced homework, which is located somewhere in his school. • Rhythm Tapper. This is a musical rhythm-based game in which the player presses a sequence of keys indicated by falling objects that overlap targets; the sequence is synchronized with music playing in the background. • Plane Dodger. This endless side-scrolling action game is inspired by modern smartphone games such as Flappy Bird and Jetpack Joyride. In this game, you control a plane that dodges enemies flying past, while at the same time trying to collect stars to earn the highest score possible. • Rectangle Destroyer. Inspired by arcade and early console games such as Breakout and Arkanoid, you move a paddle to bounce a ball into a wall of bricks to destroy them, earning points and powerups in the process. • Jigsaw Puzzle. A drag-and-drop game where you move and arrange pieces of an image to reconstruct a larger picture. • 52 Card Pickup. A drag-and-drop solitaire card game in which you sort through a scattered pile of playing cards and arrange them into organized and ordered piles by rank and suit. • Jumping Jack. This is a side-scrolling platform–style game inspired by arcade and console games such as Donkey Kong and Super Mario Bros. In this game, you help Jack the Koala collect coins and keys on his quest to reach the goal. • Treasure Quest. This is a top-view adventure game inspired by classic console games such as The Legend of Zelda. In this game, you use your sword and arrows to defeat your enemies and collect coins to use at the item shop as you find your way to the treasure. • Maze Runman. This maze-based game is inspired by arcade games such as Pac-Man and the early console game Maze Craze. In this game, you attempt to collect all the coins before being captured by a ghost that continuously follows you throughout a randomly created maze. • Starfish Collector 3D. This game is a 3D remake of the Starfish Collector game introduced in the beginning of the book and introduces 3D game programming concepts. xviii ■ INTRODUCTION Changes from the First Edition There have been a great number of changes to the content and organization of the book based on feedback from readers, students, and teachers. The major changes are listed here: • Reduced number of elementary examples; in particular, the games Cheese Please and Balloon Buster from the first edition have been removed. • New functionality has been added to the BaseActor class to simplify gathering instances of a class into lists. • Game entities are now typically written as extensions of the BaseActor class so as to increase encapsulation and reduce the amount of code required by the BaseScreen classes. • The content of Chapter 4 (“Adding Polish to Your Game”) of the first edition has been separated into Chapters 5 and 6 in the second edition, allowing for extended treatment of user-interface design and audio support. Each of these topics also has its own dedicated example game project. • The material on the bitmap font–generating program Hiero has been replaced by bitmap font–generating classes, allowing the developer to more quickly generate custom fonts from true-type font (ttf) files in code. This circumvents the need to generate bitmap font images ahead of time, which should streamline the development process. • The code for detecting the bounce angle for the ball in Rectangle Destroyer has been greatly simplified. • The drag-and-drop–related code and tilemap-related code have been refactored into their own separate classes for easier reuse in other projects. • Individual games have been reorganized into separate chapters and introduce many new game mechanics. In particular, Chapter 6 (“Additional Game Case Studies”) of the first edition has been separated into Chapters 4, 7, 8, and 9 in the second edition. The games of Chapter 7 (“Integrating Third-Party Software”) of the first edition have been separated into Chapters 11 and 12 in the second edition. • Because of the importance of tilemaps, the corresponding material has been moved into its own chapter (Chapter 10) and is used to simplify previous game projects (Starfish Collector and Rectangle Destroyer) before moving on to move advanced games in the following chapters. • The material on the physics engine has been eliminated to reduce complexity and unnecessary overhead in favor of using custom physics code. • Advanced topics have been added (maze generation in Chapter 14 and shader programming in Chapter 15). • The 3D demo from the first edition (“Pirate Cruiser”) has been replaced by the game project Starfish Collector 3D. • New appendices have been added containing advice and examples for game- design documentation and a complete JavaDoc-style listing of the extension classes developed in the book as a helpful reference.

xix