Lee Stemkoski
Java Game Development with LibGDXFrom Beginner to Professional2nd ed.
Lee Stemkoski
DEPT OF MATH & CS, ADELPHI UNIVERSITY DEPT OF MATH & CS, Garden City, New York, USA
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/9781484233238 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-3323-8e-ISBN 978-1-4842-3324-5
Library of Congress Control Number: 2018931188
© Lee Stemkoski 2018
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.
Printed on acid-free paper
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.
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 programmer. 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.

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.

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 Box2D 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.
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.
Contents
Part I: Fundamental Concepts
Part II: Intermediate Examples
Part III: Advanced Topics
Appendix A: Game Design Documentation401
Game Design Documentation Questions402
Case Study: Space Rocks405
Appendix B: Review of Java Fundamentals411
Data Types and Operators411
Control Structures412
Conditional Statements412
Repetition Statements414
Methods415
Objects and Classes416
Summary418
Appendix C: Extended Framework Class Reference419
The BaseScreen Class419
Constructor419
Fields419
Methods420
The BaseActor Class421
Constructor421
Methods421
The TilemapActor Class423
Constructor423
Fields423
Methods424
Index
About the Author and About the Technical Reviewer
About the Author
Lee Stemkoski
A352797_2_En_BookFrontmatter_Figb_HTML.jpg
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 Construct 2 , in addition to many other scholarly articles and game development tutorials.
 
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.
 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset