0%

Book Description

Learn C++ programming with a fun, real-world application that allows you to create your own games!

In Detail

Unreal Engine 4 is used to create top notch, exciting games by AAA studios, and learning to program in C++ needs some serious motivation.

Learning C++ by Creating Games With UE4 will start with the basics of C++: installing a code editor so you can begin to write C++ code. You will then learn how to write small, self-contained C++ programs that show you how to use the C++ language, without overwhelming you with too much code at the beginning. As we dig into more advanced C++ concepts, you will start to explore the functionality the UE4 engine has to offer. You will use the UE4 editor to create your own world, and then program in some seriously fun gameplay. By the end of this book, you should have a good grasp of how to program in C++.

What You Will Learn

  • Visualize and truly understand C++ programming concepts, such as how data is saved in computer memory and how program flow works
  • Write reusable code by grouping lines of code into functions
  • Learn how inheritance works-how traits of a base class are passed on to derived classes
  • Learn about dynamic allocation of new memory for your program
  • Design your own world using the UE4 editor
  • Practice programming by coding behaviors into your game world, including player inventory tracking, monsters, and NPCs

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 files e-mailed directly to you.

Table of Contents

  1. Learning C++ by Creating Games with UE4
    1. Table of Contents
    2. Learning C++ by Creating Games with UE4
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What is a game engine anyway?
      2. What will using UE4 cost me?
      3. Why don't I just program my own engine and save the 5 percent?
      4. A game's overview – the Play-Reward-Growth loop
        1. Monetization
        2. Why C++
      5. What this book covers
      6. What you need for this book
      7. Who this book is for
      8. Conventions
      9. Reader feedback
      10. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Coding with C++
      1. Setting up our project
        1. Using Microsoft Visual C++ on Windows
        2. Using XCode on a Mac
      2. Creating your first C++ program
        1. Semicolons
        2. Handling errors
        3. Warnings
      3. What is building and compiling?
        1. Scripting
          1. Exercise – ASCII art
      4. Summary
    9. 2. Variables and Memory
      1. Variables
        1. Declaring variables – touching the silicon
          1. Reading and writing to your reserved spot in memory
        2. Numbers are everything
        3. More on variables
        4. Math in C++
          1. Exercises
        5. Generalized variable syntax
        6. Primitive types
        7. Object types
          1. Exercise – Player
            1. Solution
        8. Pointers
        9. What can pointers do?
        10. Address of operator &
          1. The Null pointers
        11. cin
        12. printf()
          1. Exercise
          2. Solution
      2. Summary
    10. 3. If, Else, and Switch
      1. Branching
      2. Controlling the flow of your program
        1. The == operator
        2. Coding if statements
        3. Coding else statements
        4. Testing for inequalities using other comparison operators (>, >=, <, <=, and !=)
      3. Using logical operators
        1. The Not (!) operator
          1. Exercises
          2. Solution
        2. The And (&&) operator
        3. The Or (||) operator
      4. Our first example with Unreal Engine
        1. Exercise
        2. Solution
        3. Branching code in more than two ways
        4. The else if statement
          1. Exercise
          2. Solution
        5. The switch statement
          1. Switch versus if
          2. Exercise
          3. Solution
      5. Summary
    11. 4. Looping
      1. The while loop
        1. Infinite loops
        2. Exercises
        3. Solutions
      2. The do/while loop
      3. The for loop
        1. Exercises
        2. Solutions
      4. Looping with Unreal Engine
      5. Summary
    12. 5. Functions and Macros
      1. Functions
      2. An example of a <cmath> library function – sqrt()
      3. Writing our own functions
        1. A sample program trace
        2. Exercise
        3. Solution
      4. Functions with arguments
      5. Functions that return values
        1. Exercises
        2. Solutions
      6. Variables, revisited
        1. Global variables
        2. Local variables
        3. The scope of a variable
        4. Static local variables
        5. Const variables
        6. Function prototypes
        7. .h and .cpp files
        8. prototypes.h contains
        9. funcs.cpp contains
        10. main.cpp contains
        11. Extern variables
      7. Macros
        1. Advice – try to use const variables where possible
      8. Macros with arguments
        1. Advice – use inline functions instead of macros with arguments
      9. Summary
    13. 6. Objects, Classes, and Inheritance
      1. struct objects
        1. Member functions
          1. The this keyword
        2. Strings are objects?
        3. Invoking a member function
          1. Exercises
          2. Solutions
        4. Privates and encapsulation
        5. Some people like it public
      2. class versus struct
      3. Getters and setters
        1. Getters
        2. Setters
        3. But what's the point of get/set operations?
      4. Constructors and destructors
      5. Class inheritance
        1. Derived classes
          1. Syntax of inheritance
          2. What does inheritance do?
        2. is-a relationship
        3. protected variables
        4. Virtual functions
        5. Purely virtual functions (and abstract classes)
      6. Multiple inheritance
        1. private inheritance
      7. Putting your classes into headers
        1. .h and .cpp
        2. Exercise
      8. Summary
    14. 7. Dynamic Memory Allocation
      1. Dynamic memory allocation
        1. The delete keyword
        2. Memory leaks
      2. Regular arrays
        1. The array syntax
        2. Exercise
        3. Solutions
      3. C++ style dynamic size arrays (new[] and delete[])
      4. Dynamic C-style arrays
      5. Summary
    15. 8. Actors and Pawns
      1. Actors versus pawns
      2. Creating a world to put your actors in
      3. The UE4 editor
        1. Editor controls
        2. Play mode controls
        3. Adding objects to the scene
      4. Starting from scratch
        1. Adding light sources
        2. Collision volumes
          1. Adding collision detection for the objects editor
      5. Adding an actor to the scene
      6. Creating a player entity
        1. Inheriting from UE4 GameFramework classes
          1. Associating a model with the Avatar class
            1. Downloading free models
        2. Loading the mesh
          1. Creating a blueprint from our C++ class
      7. Writing C++ code that controls the game's character
        1. Making the player an instance of the Avatar class
        2. Setting up controller inputs
          1. Exercise
          2. Solution
        3. Yaw and pitch
      8. Creating non-player character entities
      9. Displaying a quote from each NPC dialog box
        1. Displaying messages on the HUD
        2. Using TArray<Message>
          1. Exercise
          2. Solution
        3. Triggering an event when it is near an NPC
          1. Make the NPC display something to the HUD when something is nearby
          2. Exercises
          3. Solutions
      10. Summary
    16. 9. Templates and Commonly Used Containers
      1. Debugging the output in UE4
      2. UE4's TArray<T>
        1. An example that uses TArray<T>
        2. Iterating a TArray
          1. The vanilla for loop and square brackets notation
            1. The vanilla for loop and square brackets notation
            2. Iterators
        3. Finding whether an element is in the TArray
      3. TSet<T>
        1. Iterating a TSet
        2. Intersecting TSet
        3. Unioning TSet
        4. Finding TSet
      4. TMap<T, S>
        1. A list of items for the player's inventory
        2. Iterating a TMap
      5. C++ STL versions of commonly used containers
        1. C++ STL set
          1. Finding an element in a <set>
          2. Exercise
          3. Solution
        2. C++ STL map
          1. Finding an element in a <map>
          2. Exercise
          3. Solution
      6. Summary
    17. 10. Inventory System and Pickup Items
      1. Declaring the backpack
        1. Forward declaration
        2. Importing assets
        3. Attaching an action mapping to a key
      2. Base class PickupItem
        1. The root component
          1. Getting the avatar
          2. Getting the player controller
          3. Getting the HUD
      3. Drawing the player inventory
        1. Using HUD::DrawTexture()
          1. Exercise
        2. Detecting inventory item clicks
          1. Dragging elements
          2. Exercises
      4. Summary
    18. 11. Monsters
      1. Landscape
        1. Sculpting the landscape
      2. Monsters
        1. Basic monster intelligence
          1. Moving the monster – steering behavior
          2. The discrete nature of monster motion
          3. Monster SightSphere
      3. Monster attacks on the player
        1. Melee attacks
          1. Defining a melee weapon
            1. Coding for a melee weapon in C++
            2. Downloading a sword
            3. Creating a blueprint for your melee weapon
        2. Sockets
          1. Creating a skeletal mesh socket in the monster's hand
          2. Attaching the sword to the model
          3. Code to equip the player with a sword
          4. Triggering the attack animation
            1. Blueprint basics
            2. Modifying the animation blueprint for Mixamo Adam
            3. Code to swing the sword
        3. Projectile or ranged attacks
          1. Bullet physics
          2. Adding bullets to the monster class
        4. Player knockback
      4. Summary
    19. 12. Spell Book
      1. The particle systems
        1. Changing particle properties
        2. Settings for the blizzard spell
      2. Spell class actor
        1. Blueprinting our spells
        2. Picking up spells
          1. Creating blueprints for PickupItems that cast spells
      3. Attaching right mouse click to cast spell
        1. Writing the avatar's CastSpell function
          1. Instantiating the spell – GetWorld()->SpawnActor()
          2. if(spell)
          3. spell->SetCaster(this)
        2. Writing AMyHUD::MouseRightClicked()
          1. Activating right mouse button clicks
      4. Creating other spells
        1. The fire spell
        2. Exercises
      5. Summary
    20. Index
18.118.186.143