Book Image

Mastering LibGDX Game Development

By : Patrick Hoey
Book Image

Mastering LibGDX Game Development

By: Patrick Hoey

Overview of this book

Table of Contents (18 chapters)
Mastering LibGDX Game Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

 

"It is pitch black. You are likely to be eaten by a grue."

 
 --Zork

Some of my fondest video game memories belong to text-based adventure games. Zork was my gateway game into the realm of role-playing games on the computer. RPGs offered excitement and challenges of adventuring into unknown lands ripe with unknown dangers, and helped fuel my imagination. This book is a testament to that imagination, one which refused to be extinguished by age or experience. My hope is that your RPG will keep the burning flames of imagination alive and provide an experience with memories that will last for a lifetime.

The theory, implementation, and lessons taught within these pages should help guide you through the development process of creating your own RPG game. There are many moving parts that add to the complexity of developing a video game, especially RPGs, but the intent of this book is to provide you with a step-by-step guide to the development process. I developed BludBourne, the reference implementation game for this book, at the same time I was writing this book. If there were any issues that I came across during development, or if I found a nice design pattern that solved a problem, I made sure to document the experience in this book so that you would not have to deal with the same pitfalls.

You may have heard about various engines and frameworks, and even tried them, but instead of creating a complete commercial game, you ended up in disappointment, lost in a sea of technologies. Maybe you always wanted to create an RPG, but found the creation process overwhelming. Maybe you would visit forums and post questions, but all you ever got were common replies of derision, such as "Just create your game in RPG Maker." This book simplifies this approach by walking you through the process so that you can extend and customize BludBourne for your own commercial release. The framework that will allow us to bridge the gap from conception of an idea to an actual playable game is LibGDX.

LibGDX is a Java-based framework developed with a heavy emphasis on performance, and it includes cross-platform support out of the box (Windows, OS X, Linux, iOS, Android, and HTML5), and provides all the low-level functionality you need so that you can focus on developing your game instead of battling with the platform. LibGDX also has an engaged and responsive community, active maintenance, and is available for free without a prohibitive license. There are many beginner tutorials using LibGDX, but the aim of this book is to make use of LibGDX libraries for more advanced, complex features used in video games.

By the end of this book, you will have a foundation in game development principles and a set of tools that will help you realize your dreams.

What this book covers

Chapter 1, As the Prophecy Foretold, a Hero is Born, introduces you to the fundamentals and specific features of RPG video games, and discusses how this book will help build foundational knowledge for a commercial RPG. This chapter will also walk you through the basics of video game architecture, with a high-level overview of the component layout and application lifecycle in LibGDX. Finally, after learning about setting up your development and build environment, you will run your first demo application.

Chapter 2, Welcome to the Land of BludBourne, initially discusses how to create maps for BludBourne with a tile editor and how to load them using asset management classes. You will then implement your main render loop with a camera for displaying your loaded maps. We will then discuss some features specific to maps, including spawn points and a portal system. Finally, you will learn about adding animation to your player sprite and implementing input handling so that your player can move around the game world.

Chapter 3, It's Pretty Lonely in BludBourne…, discusses how to implement the Entity Component System design pattern for BludBourne. We will then cover scripting support using JSON to define NPC properties. Finally, we will implement a physics component with collision detection and an input component for the NPCs' movement.

Chapter 4, Where Do I Put My Stuff?, covers HUD layouts with skins. We will learn about integrating player stats into the UI. We will then apply this knowledge by implementing a drag and drop inventory system for your player. Finally, we will discuss how to persist player state with save and load game profiles.

Chapter 5, Time to Breathe Some Life into This Town, discusses the theory behind dialog trees and implements an interactive speech system for the NPC characters. Finally, we will develop shop store UIs for the player with item and money transactions.

Chapter 6, So Many Quests, So Little Time…, discusses quest systems, including dependency graph theory and implementation. Finally, we will create a quest log UI, including the steps involved with creating scripts for quests.

Chapter 7, Time to Show These Monsters Who's the Boss, discusses how to implement a battle system with a UI including enemy NPC battle mechanics. We will then look at how we can connect HUD updates to state changes in BludBourne. We will cover a few tricks for implementing the consumption of items from the player's inventory. Finally, we will develop a leveling system for the player.

Chapter 8, Oh, No! Looks Like Drama!, discusses how to integrate sound and music into the world of BludBourne. We will also look at how to create cutscenes and integrate them into the game.

Chapter 9, Time to Set the Mood, covers an assorted list of special effects that can give your RPG some nice polish. We will first learn about creating transitions between screens. We will then learn about the theory behind a shake camera class and implement it. We will then look at how a static lighting model fits into BludBourne, including implementing a day-to-night cycle. Finally, we will cover particle effects that can used to make the spells pop and torches smoke.

Chapter 10, Prophecy Fulfilled, Our Hero Awaits the Next Adventure, covers deployment topics for your game, including discussing digital distribution platforms. We will then look at security measures, including obfuscating save game profiles, executable jars, native launchers, and obfuscating the final packaged JAR. Finally, we will look at a few tips and tricks regarding test coverage for builds and some debugging tips.

What you need for this book

Throughout the book, I have mentioned various technologies and tools that can help at certain stages in the development cycle. I have recommended mostly free software tools and dependencies. However, keep in mind that some may require a separate license for commercial purposes. As a testament to the open source community, I created BludBourne entirely from these free resources.

LibGDX is a cross-platform game development framework that can run on a Windows PC, Linux, Android device, or Mac OS X. The development for this book specifically supports Windows (7/8), so keep this in mind when using the source for BludBourne as there may be some platform-specific considerations outside of Windows.

As a quick summary of tools and libraries used for this book, I have listed them here (may not be an exhaustive list):

The installation and usage instructions for additional tools are provided where necessary.

Who this book is for

If you have always wanted to create an RPG video game but found the creation process overwhelming, either due to lack of tutorials or by getting lost in a sea of game-related technologies, engines or frameworks, then this book is for you.

This book will walk you through the entire development process of creating an RPG title from scratch using the LibGDX framework and it can be used as a reference by everyone from a team developing their first commercial title to the solo hobbyist.

This book does expect that you have software engineering experience, including familiarity with object-oriented programming in the Java language and an understanding of UML.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The processInput() method is the primary business logic that drives this class."

A block of code is set as follows:

public class DesktopLauncher {
  public static void main (String[] arg) {
    LwjglApplicationConfiguration config = new 
            LwjglApplicationConfiguration();
    new LwjglApplication(new BludBourne(), config);
  }
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public class DesktopLauncher {
  public static void main (String[] arg) {
    LwjglApplicationConfiguration config = new 
            LwjglApplicationConfiguration();
    new LwjglApplication(new BludBourne(), config);
  }
}

Any command-line input or output is written as follows:

C:\BludBourne>tree /F /A

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Adding a new tileset is as easy as clicking on the New icon in the Tilesets area."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you. For the most current version, you can grab the latest snapshot from this link: https://github.com/patrickhoey/BludBourne.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/MasteringLibGDXGameDevelopment_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.