You are previewing C++ Game Development Cookbook.
O'Reilly logo
C++ Game Development Cookbook

Book Description

Over 90 recipes to get you creating modern, fast, and high-quality games with C++

About This Book

  • Level up your game programming skills with insightful recipes on building games in C++

  • Analyze the less commonly discussed problems with C++ applications to develop the best games

  • Improve the performance of your games with the new multi-threading and networking features of C++11

  • Who This Book Is For

    This book is ideal for aspiring game developers who are proficient in C++ programming and are interested in developing games with C++. Some basic knowledge of game programming will be useful but is not necessary.

    What You Will Learn

  • Explore the basics of game development to build great and effective features for your game

  • Develop your first text-based game using the various concepts of object-oriented programming

  • Use algorithms when developing games with various sorting and searching techniques

  • Exploit data structures in a game’s development for data storage

  • Create your first 2D game using GDI library and sprite sheet.

  • Build your first advanced 2D game of space invaders using patterns such as observer, fly-weight, abstract factory, command, state, and more

  • In Detail

    C++ is one of the preferred languages for game development as it supports a variety of coding styles that provides low-level access to the system. C++ is still used as a preferred game programming language by many as it gives game programmers control of the entire architecture, including memory patterns and usage. However, there is little information available on how to harness the advanced features of C++ to build robust games.

    This book will teach you techniques to develop logic and game code using C++. The primary goal of this book is to teach you to create high-quality games using C++ game programming scripts and techniques, regardless of the library or game engine you use. It will show you how to make use of the object-oriented capabilities of C++ so you can write well-structured and powerful games of any genre. The book also explores important areas such as physics programming and audio programming, and gives you other useful tips and tricks to improve your code.

    By the end of this book, you will be competent in game programming using C++, and will be able to develop your own games in C++.

    Style and approach

    Every recipe of this guide covers a task that will help you build different aspects of a game, such as taking player input and displaying the output, using control flow to implement decision making, and so on. Each recipe begins with gentle introduction and key concepts, has illustrated examples of use, and ends with a detailed but informative description of the inner workings.

    Downloading the example code for this book. 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 code file.

    Table of Contents

    1. C++ Game Development Cookbook
      1. Table of Contents
      2. C++ Game Development Cookbook
      3. Credits
      4. About the Author
      5. About the Reviewer
      6. www.PacktPub.com
        1. eBooks, discount offers, and more
          1. Why Subscribe?
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Sections
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Game Development Basics
        1. Introduction
        2. Installing an IDE on Windows
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Choosing the right source control tool
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Using call stacks for memory storage
          1. Getting ready
          2. How to do it...
          3. How it works…
        5. Using recursions cautiously
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        6. Using pointers to store memory addresses
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        7. Casting between different datatypes
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Managing memory more effectively using dynamic allocation
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Understanding the error messages
        9. Using bitwise operations for advanced checks and optimization
          1. Getting ready
          2. How to do it…
          3. How it works…
      9. 2. Object-Oriented Approach and Design in Games
        1. Introduction
        2. Using classes for data encapsulation and abstraction
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Using polymorphism to reuse code
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Using copy constructors
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Use operator overloading to reuse operators
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Use function overloading to reuse functions
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Using files for input and output
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Creating your first simple game
          1. Getting ready
          2. How to do it…
          3. How it works…
        9. Templates – when to use them
          1. Getting ready
          2. How to do it…
          3. How it works…
      10. 3. Data Structures in Game Development
        1. Introduction
        2. Using more advanced data structures
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Using linked lists to store data
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Using stacks to store data
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Using queues to store data
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Using trees to store data
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Using graphs to store data
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Using STL lists to store data
          1. Getting ready
          2. How to do it…
          3. How it works…
        9. Using STL maps to store data
          1. Getting ready
          2. How to do it…
          3. How it works…
        10. Using STL hash tables to store data
          1. Getting ready
          2. How to do it…
          3. How it works…
      11. 4. Algorithms for Game Development
        1. Introduction
        2. Using sorting techniques to arrange items
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Using searching techniques to look for an item
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Finding the complexity of an algorithm
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Finding the endian-ness of a device
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Using dynamic programming to break down a complex problem
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Using greedy algorithms to solve problems
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Using divide and conquer algorithms to solve problems
          1. Getting ready
          2. How to do it…
          3. How it works…
      12. 5. Event-Driven Programming – Making Your First 2D Game
        1. Introduction
        2. Starting to make a Windows game
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Using Windows classes and handles
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Creating your first window
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Adding keyboard and mouse controls with text output
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Using Windows resources with GDI
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Using dialogs and controls
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Using sprites
          1. Getting ready
          2. How to do it…
          3. How it works…
        9. Using animated sprites
          1. Getting ready
          2. How to do it…
          3. How it works…
      13. 6. Design Patterns for Game Development
        1. Introduction
        2. Using the singleton design pattern
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Using the factory method
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Using the abstract factory method
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Using the observer pattern
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Using the flyweight pattern
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Using the strategy pattern
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Using the command design pattern
          1. Getting ready
          2. How to do it…
          3. How it works…
        9. Creating an advanced game using design patterns
          1. Getting ready
          2. How to do it…
          3. How it works…
      14. 7. Organizing and Backing Up
        1. Introduction
        2. Versions of source control
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Installing a versioning client
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Selecting a host to save your data
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Adding source control – committing and updating your code
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Resolving conflicts
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Creating a branch
          1. Getting ready
          2. How to do it...
          3. How it works...
      15. 8. AI in Game Development
        1. Introduction
        2. Adding artificial intelligence to a game
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Using heuristics in a game
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Using a Binary Space Partition Tree
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Creating a decision making AI
          1. Getting ready
          2. How to do it...
          3. How it works…
        6. Adding behavioral movements
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Using neural network
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Using genetic algorithms
          1. Getting ready
          2. How to do it…
          3. How it works…
            1. Step 1 (Initial Population)
            2. Step 2 (Fitness function)
            3. Step 3 Cross-over
            4. Step 4 Mutate
        9. Using other waypoint systems
          1. Getting ready
          2. How to do it…
          3. How it works…
      16. 9. Physics in Game Development
        1. Introduction
        2. Using physics rules in your game
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Making things collide
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Installing and integrating Box2D
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Making a basic 2D game
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Making a 3D game
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Creating a particle system
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Using ragdoll in your game
          1. Getting ready
          2. How to do it…
          3. How it works…
      17. 10. Multithreading in Game Development
        1. Introduction
        2. Concurrency in games – creating a thread
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Joining and detaching a thread
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Passing arguments to a thread
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Avoiding deadlocks
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Data race and mutex
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Writing a thread-safe class
          1. Getting ready
          2. How to do it…
          3. How it works…
      18. 11. Networking in Game Development
        1. Introduction
        2. Understanding the different layers
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Selecting the appropriate protocol
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Serializing the packets
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Using socket programming in games
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Sending the data
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Receiving the data
          1. Getting ready
          2. How to do it…
          3. How it works…
        8. Dealing with lag
          1. Getting ready
          2. How to do it…
          3. How it works…
        9. Using synchronized simulation
          1. Getting ready
          2. How to do it…
          3. How it works…
        10. Using area of interest filtering
          1. Getting ready
          2. How to do it…
          3. How it works…
        11. Using local perception filter
          1. Getting ready
          2. How to do it…
          3. How it works…
      19. 12. Audio in Game Development
        1. Introduction
        2. Installing FMOD
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Adding background music
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Adding sound effects
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Creating a sound effect manager
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Dealing with multiple sound file names
          1. Getting ready
          2. How to do it…
          3. How it works…
      20. 13. Tips and Tricks
        1. Introduction
        2. Effectively commenting your code
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Using bit fields in a struct
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Writing a sound technical design document
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Using the const keyword to optimize your code
          1. Getting ready
          2. How to do it…
          3. How it works…
        6. Using bit shift operators in an enum
          1. Getting ready
          2. How to do it…
          3. How it works…
        7. Using the new lambda function of C++ 11
          1. Getting ready
          2. How to do it…
          3. How it works…
      21. Index