Procedural Content Generation for C++ Game Development
eBook - ePub

Procedural Content Generation for C++ Game Development

  1. 304 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Procedural Content Generation for C++ Game Development

Book details
Book preview
Table of contents
Citations

About This Book

Get to know techniques and approaches to procedurally generate game content in C++ using Simple and Fast Multimedia Library

About This Book

  • This book contains a bespoke Simple and Fast Multimedia Library (SFML) game engine with complete online documentation
  • Through this book, you'll create games that are non-predictable and dynamic and have a high replayability factor
  • Get a breakdown of the key techniques and approaches applied to a real game.

Who This Book Is For

If you are a game developer who is familiar with C++ and is looking to create bigger and more dynamic games, then this book is for you. The book assumes some prior experience with C++, but any intermediate concepts are clarified in detail. No prior experience with SFML is required.

What You Will Learn

  • Discover the systems and ideology that lie at the heart of procedural systems
  • Use Random number generation (RNG) with C++ data types to create random but controlled results
  • Build levels procedurally with randomly located items and events
  • Create dynamic game objects at runtime
  • Construct games using a component-based approach
  • Assemble non-predictable game events and scenarios
  • Operate procedural generation to create dynamic content fast and easily
  • Generate game environments for endless replayability

In Detail

Procedural generation is a growing trend in game development. It allows developers to create games that are bigger and more dynamic, giving the games a higher level of replayability. Procedural generation isn't just one technique, it's a collection of techniques and approaches that are used together to create dynamic systems and objects. C++ is the industry-standard programming language to write computer games. It's at the heart of most engines, and is incredibly powerful. SFML is an easy-to-use, cross-platform, and open-source multimedia library. Access to computer hardware is broken into succinct modules, making it a great choice if you want to develop cross-platform games with ease.

Using C++ and SFML technologies, this book will guide you through the techniques and approaches used to generate content procedurally within game development.

Throughout the course of this book, we'll look at examples of these technologies, starting with setting up a roguelike project using the C++ template. We'll then move on to using RNG with C++ data types and randomly scattering objects within a game map. We will create simple console examples to implement in a real game by creating unique and randomised game items, dynamic sprites, and effects, and procedurally generating game events. Then we will walk you through generating random game maps. At the end, we will have a retrospective look at the project.

By the end of the book, not only will you have a solid understanding of procedural generation, but you'll also have a working roguelike game that you will have extended using the examples provided.

Style and approach

This is an easy-to-follow guide where each topic is explained clearly and thoroughly through the use of a bespoke example, then implemented in a real game project.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Procedural Content Generation for C++ Game Development by Dale Green in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming Games. We have over one million books available in our catalogue for you to explore.

Information

Year
2016
ISBN
9781785886713
Edition
1

Procedural Content Generation for C++ Game Development


Table of Contents

Procedural Content Generation for C++ Game Development
Credits
About the Author
Acknowledgment
About the Reviewer
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
Extra Exercises
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. An Introduction to Procedural Generation
Procedural generation versus random generation
Procedural generation
Random generation
Introducing randomness
Pseudorandom number generation
Why computers can't generate truly random numbers
Generating random numbers in C++
Generating random numbers within a range
Seeds
Defining seeds
Using seeds
Generating random seeds during the runtime
Controlled randomness is the key to generating random numbers
The use of procedural generation in games
Saving space
Map generation
Texture creation
Animation
Sound
Benefits of procedural generation
Larger games can be created
Procedural generation can be used to lower budgets
An increase in gameplay variety
An increase in replayability
The drawbacks of procedural generation
More taxing on the hardware
Worlds can feel repetitive
You sacrifice quality control
You may generate an unplayable world
It is hard to script set game events
A brief history of rogue-like games
How we'll implement procedural generation
Populating environments
Creating unique game objects
Creating unique art
Audio manipulation
Behavior and mechanics
Dungeon generation
Component-based design
The complete game
Exercises
Summary
2. Project Setup and Breakdown
Choosing an IDE
Microsoft Visual Studio
Code::Blocks
Other IDEs
Build systems
Breaking down the game template
Download templates
The class diagram
The object hierarchy
Level data
Collision
Input
Simple and Fast Multimedia Library (SFML)
Defining SFML
Why we'll be using SFML
Learning SFML
Alternatives
Polymorphism
Inheritance
Virtual functions
Pure virtual functions
Pointers and object slicing
The roguelike template setup
Downloading SFML
Linking SFML
Running the project
Adding an item
Updating and drawing
Exercises
Summary
3. Using RNG with C++ Data Types
Setting the game seed
Setting Boolean values randomly
Generating a number between 0 and 1
Choosing if an item spawns
Random number distribution
Giving the player random stats
Accessing random elements of a collection
Spawning a random item
Generating random characters
Repeating loops
Spawning a random number of items
Exercises
Summary
4. Procedurally Populating Game Environments
Potential obstacles
Keeping within the bounds of a level
Avoiding overlapping objects
Creating meaningful levels
Level tiles
Defining the spawn area
Calculating the level bounds
Checking the underlying game grid
Selecting a suitable game tile
Randomly selecting a tile
Checking whether a tile is suitable
Converting to absolute position
Spawning items at a random location
Expanding the spawning system
Using enumerators to denote an object type
Optional parameters
The complete spawn functions
Updating the spawn code
Randomly spawning enemies
Spawning random tiles
Adding a new game tile
Choosing a random tile
Implementing the SpawnRandomTiles function
Exercises
Summary
5. Creating Unique and Randomized Game Objects
Creating a random player character
Choosing a player class
An overview of sprites and textures
Setting an appropriate sprite
Buffing the player stats
Random character traits
Returning the player traits array
Setting trait sprites
Procedurally generating an enemy class
Procedural items
Random Gem and Heart classes
Random gold class
The random potion class
Creating a random potion
Determining potion pickups
Exercises
Summary
6. Procedurally Generating Art
How procedural generation is used with art
Using sprite effects and modifiers
Combining multiple textures
Creating textures from scratch
Creating complex animations
The benefits of procedurally generated art
Versatility
Cheap to produce
It requires little storage
The drawbacks of procedurally generated art
Lack of control
Repeatability
Performance heavy
Using SFML sprite modifiers
How colors work in SFML
Creating sprites of a random color
Selecting a preset color at random
Generating a color at random
Creating sprites of a random size
Saving modified sprites
Passing a texture into an image
Drawing to a RenderTexture class
Saving an image to a file
Creating enemy sprites procedurally
Breaking sprites into components
The draw setup
Randomly selecting sprite components
Loading the default armor textures
Choosing the armor tier
Rendering the armor textures
Rendering the final textures
Overriding the default draw behavior
Debugging and testing
Editing the game tiles
Exercises
Summary
7. Procedurally Modifying Audio
An introduction to SFML audio
sf::Sound versus sf::Music
sf::SoundBuffer
Selecting a random main track
Adding sound effects
Editing sound effects
Playing a sound function
The audio listener
Creating a fluctuation in a pitch
3D sound – spatialization
The audio listener
The minimum distance
Attenuation
The position of the sound
Fixed positions
Moving positions
Exercises
Summary
8. Procedural Behavior and Mechanics
An introduction to pathfinding
What is a pathfinding algorithm?
Dijkstra's algorithm
The A* algorithm
A breakdown of A*
Representing a level as nodes
The open and closed list
The H, G, and F costs
The H value
The G value
The F value
The Manhattan distance
Parenting nodes
The pseudo-algorithm
Coding the A* pathfinding algorithm
The Tile datatype
Creating supporting functions
The Level class
The Enemy class
Variable declarations
Precalculating the H values
Defining the main loop
Finding the adjacent nodes
Calculating the G and F costs
Calculating the G and F cost
Checking for superior paths
Creating the final path
Implementing A* in the game
Enabling the enemy to follow a path
Calling the pathfinding behavior
Viewing our path
Procedurally generated level goals
The variable and function declarations
Generating a random goal
Checking whether a goal is complete
Drawing the goal on the screen
Exercises
Summary
9. Procedural Dungeon Generation
The benefits of procedural level design
Replayability
A reduction in development time
Larger game worlds
Considerations
A lack of control
Required computing power
Suitability
An overview of dungeon generation overview
Generating rooms
Generating a maze
Connecting rooms...

Table of contents

  1. Procedural Content Generation for C++ Game Development