Procedural Content Generation for Unity Game Development
Table of Contents
Procedural Content Generation for Unity Game Development
Credits
Disclaimer
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Pseudo Random Numbers
Introducing PCG
Usage of PCG
Application of PCG
Pseudo random numbers
Random versus pseudo random numbers
PRNs in PCG
Random Hello World
Classic Hello World
PCG Hello World
Challenge
Summary
2. Roguelike Games
An introduction to Roguelike games
Why Roguelike?
Our own Roguelike project
Setting up the project
Importing the base project
File overview
Animation
Fonts
Prefabs
Scenes
Scripts
Summary
3. Generating an Endless World
Data structure choice
Array
Linked list
Dictionary
PCG algorithm overview
Scene setup
Player positioning
Camera following
Layers
Initial Game Board
Connecting code
The PCG Game Board
Summary
4. Generating Random Dungeons
Algorithm design
Algorithm overview
The grid
Essential path
Random path and chambers
Filling in the rest of the gird
Placing the entrance and exit
Algorithm summary
Data structures
Back to the map
Queue
Prefab setup
An exit sign
DungeonManager
BoardManager
Player
GameManager
Back to the Unity Editor
Seeding the dungeon
Challenge
Summary
5. Randomized Items
Generating health items in the game world
Implementing health item generation
Setting up sprites
Generating items in the dungeon
The Chest prefab
Chest implementation
Spawning the chest
The Item prefab
Item code
Adding player to item interaction
Summary
6. Generating Modular Weapons
PCG with modules
Statistics of modular PCG
Creating and configuring new sprites
Creating a multiple image prefab
Modular weapon scripts
Adding a spawn point
Adding a weapon pick up
Adding scripted weapon animation
Adding character facing directions
Summary
7. Adaptive Difficulty
Setting up sprites
Adding enemies to the world board
Adding enemies to the Dungeon Board
Fighting the enemy
Adaptive difficulty
Enemy AI
Finishing up
Summary
8. Generating Music
Concept of music
Tempo
Melody
Repetition
Procedurally generated music algorithm
Measure
Dividing the measure
The base line
Setting up the script
The Sound Manager script
Adding tension
Summary
9. Generating a 3D Planet
Adding a third dimension
3D versus 2D
Know your geometry
Working with the Unity primitive sphere
Generating a sphere
Adding randomization
Bad time and space complexities
Multi mesh planet
Exploring the planet
Summary
10. Generating the Future
Models
Items
Levels
Texture
Terrain
Physics
Animation
AI
Story
The player sandbox
Summary
Index
Procedural Content Generation for Unity Game Development
Copyright © 2016 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, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be 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.
First published: January 2016
Production reference: 1220116
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-747-3
www.packtpub.com
Author
Ryan Watkins
Reviewers
Joshua Byrom
Michele Pirovano
Till Riemer
Gennaro Vessio
Acquisition Editor
Prachi Bisht
Content Development Editor
Merint Thomas Mathew
Technical Editor
Vivek Arora
Copy Editor
Merilyn Pereira
Project Coordinator
Francina Pinto
Proofreader
Safis Editing
Indexer
Rekha Nair
Graphics
Jason Monteiro
Production Coordinator
Manu Joseph
Cover Work
Manu Joseph
The Unity name, logo, brand, and other trademarks or images featured or referred to within this book are licensed from and are the sole property of Unity Technologies. This book, its author, or the publisher are not affiliated with, endorsed by, or sponsored by Unity Technologies or any of its affiliates.
Ryan Watkins was digitized and absorbed into his computer at an early age. In the digital realm, he learned the importance of video games and the balance they brought to the ecosystem of computing. Video games strive to always push the boundaries of what we know to be true while being a super-charged source of fun. Ryan formed friendships with many of the video games he encountered on his digital journeys, and in return, they shared the secrets of their creation with him. He has since returned to the physical world to share those secrets with the rest of us.
Joshua Byrom has been programming and gaming for over two decades, and has written numerous articles on the subjects of game programming and artificial intelligence. Around the age of eight, he was introduced to computers by his father, which generated in him a deep interest for computer science, particularly computer programming.
Since then, Joshua has written code for companies such as BMC Solutions Inc., AutoTrader.com, and Elite Property Services LLC. He has also worked for the army, where he wrote genetic algorithms for the U.S. Military. Currently, he works as a software architect, where he develops and maintains web applications for local lawyers, realtors, and retailers.
In addition, Joshua writes programming articles for online publishing, runs a small business that creates and publishes independent mobile and web applications, and provides code consulting for indie start-ups.
Currently, Joshua is located in Newnan, GA, and when he isn't lost thousands of lines deep in code, he likes to read both prose and poetry, or play video games.
Michele Pirovano is a freelance game developer and game researcher based in Bergamo, Italy. He holds a PhD in computer science from the Politecnico di Milano, where he graduated with a thesis on the design of autonomous exergaming systems.
His main interest is the application of artificial intelligence, procedural content generation, and complex mathematical systems to video games. He...